this.BX=this.BX||{};this.BX.UI=this.BX.UI||{};(function(e,t,s,a,i,l,r,o,n,c,d,b){"use strict";let h=e=>e,v,p,u,m;var g=babelHelpers.classPrivateFieldLooseKey("parent");class P extends n.EventEmitter{constructor(){super();this.cache=new o.Cache.MemoryCache;Object.defineProperty(this,g,{writable:true,value:void 0});this.setEventNamespace("Main.Avatar.Editor")}getPriority(){return this.constructor.priority}setParentTab(e){babelHelpers.classPrivateFieldLooseBase(this,g)[g]=e}getHeaderContainer(){return this.cache.remember("headerContainer",(()=>{const e=this.constructor.code;const t=this.getHeader();if(t===null){return o.Tag.render(v||(v=h`<span style="display: none;" data-bx-role="tab-header"  data-bx-state="hidden" data-bx-name="${0}"></span>`),e)}return o.Tag.render(p||(p=h`<span class="ui-avatar-editor__tab-button-item" data-bx-role="tab-header" data-bx-state="visible" data-bx-name="${0}">${0}</span>`),e,t)}))}getHeader(){if(babelHelpers.classPrivateFieldLooseBase(this,g)[g]!==null)return this.constructor.code.toUpperCase();return null}getBodyContainer(){return this.cache.remember("bodyContainer",(()=>{const e=this.constructor.code;return o.Tag.render(u||(u=h`
				<div class="ui-avatar-editor__content-block ui-avatar-editor__${0}-block" data-bx-role="tab-body" data-bx-name="${0}">${0}</div>`),e,e,this.getBody())}))}getBody(){const e=this.constructor.code;return this.cache.remember("body",(()=>o.Tag.render(m||(m=h`
			<div>
				${0}
			</div>`),e.toUpperCase())))}inactivate(){if(babelHelpers.classPrivateFieldLooseBase(this,g)[g]){babelHelpers.classPrivateFieldLooseBase(this,g)[g].getHeaderContainer().removeAttribute("data-bx-active");o.Dom.removeClass(babelHelpers.classPrivateFieldLooseBase(this,g)[g].getHeaderContainer(),"ui-avatar-editor__tab-button-active")}this.getHeaderContainer().removeAttribute("data-bx-active");o.Dom.removeClass(this.getHeaderContainer(),"ui-avatar-editor__tab-button-active");this.getBodyContainer().removeAttribute("data-bx-active");this.emit("onInactive");return this}activate(){if(babelHelpers.classPrivateFieldLooseBase(this,g)[g]){babelHelpers.classPrivateFieldLooseBase(this,g)[g].getHeaderContainer().setAttribute("data-bx-active","Y");o.Dom.addClass(babelHelpers.classPrivateFieldLooseBase(this,g)[g].getHeaderContainer(),"ui-avatar-editor__tab-button-active")}this.getHeaderContainer().setAttribute("data-bx-active","Y");o.Dom.addClass(this.getHeaderContainer(),"ui-avatar-editor__tab-button-active");this.getBodyContainer().setAttribute("data-bx-active","Y");this.emit("onActive");return this}showError({message:e,code:t}){const s=this.getBody().querySelector('[data-bx-role="error-container"]');if(s){s.innerText=e||t}o.Dom.addClass(this.getBodyContainer(),"ui-avatar-editor--error")}static isAvailable(){return true}static get code(){return"default"}}P.priority=1;let L=e=>e,B;var F=babelHelpers.classPrivateFieldLooseKey("isCameraEnabled");class H extends P{getHeader(){return null}getBody(){return this.cache.remember("body",(()=>{const e=o.Tag.render(B||(B=L`
				<div>
					<div class="ui-avatar-editor__camera-block-image">
						<div class="ui-avatar-editor__btn-back" data-bx-role="button-back"></div>
						<div class="ui-avatar-editor__user-loader-item">
							<div class="ui-avatar-editor__loader">
								<svg class="ui-avatar-editor__circular" viewBox="25 25 50 50">
									<circle class="ui-avatar-editor__path" cx="50" cy="50" r="20" fill="none" stroke-width="1" stroke-miterlimit="10"/>
								</svg>
							</div>
						</div>
						<div class="ui-avatar-editor__error">
							<span>
								${0}
							</span>
							<span data-bx-role="tab-camera-error"></span>
						</div>
						<div class="ui-avatar-editor__camera-block-image-inner">
							<video autoplay></video>
						</div>
					</div>
					<div class="ui-avatar-editor__button-layout" data-bx-role="camera-button">
						<div class="ui-avatar-editor__button">
							<span class="ui-avatar-editor__button-icon"></span>
						</div>
					</div>
				</div>
			`),o.Loc.getMessage("JS_AVATAR_EDITOR_ERROR"));const t=e.querySelector("VIDEO");t.addEventListener("playing",(s=>{const a=e.clientWidth,i=e.clientHeight,l=t.clientWidth,r=t.clientHeight,n=Math.max(l>0?a/l:1,r>0?i/r:1),c=(l*n-l)/2+(a-l*n)/2,d=(r*n-r)/2+(i-r*n)/2;o.Dom.adjust(t.parentNode,{style:{width:l+"px",height:r+"px",transform:"translate("+Math.ceil(c)+"px, "+Math.ceil(d)+"px) scale("+n+", "+n+")"}})}));e.querySelector('[data-bx-role="camera-button"]').onclick=()=>{this.emit("onSetFile",t)};e.querySelector('[data-bx-role="button-back"]').onclick=()=>{this.emit("onClickBack")};return e}))}inactivate(){this.stopStreaming();return super.inactivate()}activate(){this.startStreaming();return super.activate()}startStreaming(){const e=this.getBody().querySelector("VIDEO");e.setAttribute("active","Y");navigator.mediaDevices.getUserMedia({audio:false,video:{width:{max:1024,min:640,ideal:1024},height:{max:860,min:480,ideal:860}}}).then((function(t){if(e.hasAttribute("active")){e.srcObject=t}else{t.getTracks()[0].stop()}})).catch((e=>{this.getBody().querySelector('[data-bx-role="tab-camera-error"]').innerHTML=o.Text.encode(e)}))}stopStreaming(){const e=this.getBody().querySelector("VIDEO");e.removeAttribute("active");e.pause();e.src="";if(e.srcObject){e.srcObject.getTracks()[0].stop()}}static check(){if(babelHelpers.classPrivateFieldLooseBase(this,F)[F]===null){if(navigator.mediaDevices&&navigator.mediaDevices.enumerateDevices){navigator.mediaDevices.enumerateDevices().then((e=>{babelHelpers.classPrivateFieldLooseBase(this,F)[F]=Array.from(e).filter((function(e){return e.kind==="videoinput"})).length>0})).catch((()=>{babelHelpers.classPrivateFieldLooseBase(this,F)[F]=false}))}else{babelHelpers.classPrivateFieldLooseBase(this,F)[F]=false}}}static isAvailable(){this.check();return babelHelpers.classPrivateFieldLooseBase(this,F)[F]}static get code(){return"camera"}}H.priority=2;Object.defineProperty(H,F,{writable:true,value:null});var f=babelHelpers.classPrivateFieldLooseKey("ajaxRepo");class y{static saveMask({id:e,title:t,accessCode:s},a){if(o.Loc.getMessage("USER_ID")<=0){return}const i=new FormData;i.append("id",e);i.append("title",t);if(s.length>0){Array.from(s).forEach(((e,t)=>{i.append("accessCode["+t+"][0]",e[0]);i.append("accessCode["+t+"][1]",e[1])}))}else{i.append("accessCode[]","")}if(a instanceof Blob){i.append("file[changed]","Y");i.append("file",a,a["name"])}else{i.append("file[changed]","N")}return o.ajax.runAction("ui.avatar.mask.save",{data:i,analyticsLabel:{ui:"avatarMask",actionType:"edit",action:"save"}})}static getMaskList(e,{page:t,size:s}){return new Promise(((a,i)=>{o.ajax.runAction("ui.avatar.mask.get"+e,{data:{},navigation:{page:t,size:s},analyticsLabel:{ui:"avatarMask",actionType:"read",action:"list"}}).then((({data:{groupedItems:e}})=>{a(e)})).catch(i)}))}static getMaskInitialInfo({size:e,recentlyUsedListSize:t}){return new Promise(((s,a)=>{if(babelHelpers.classPrivateFieldLooseBase(this,f)[f]["getMaskInitialInfo"]){return s(babelHelpers.classPrivateFieldLooseBase(this,f)[f]["getMaskInitialInfo"])}o.ajax.runAction("ui.avatar.mask.getMaskInitialInfo",{data:{recentlyUsedListSize:t},navigation:{page:1,size:e},analyticsLabel:{ui:"avatarMask",actionType:"read",action:"initialInfo"}}).then((({data:{initialInfo:e}})=>{babelHelpers.classPrivateFieldLooseBase(this,f)[f]["getMaskInitialInfo"]=e;s(e)})).catch(a)}))}static getMaskAccessCode(e){return o.ajax.runAction("ui.avatar.mask.getMaskAccessCode",{data:{id:e},analyticsLabel:{ui:"avatarMask",actionType:"edit",action:"accessCode"}})}static deleteMask(e){return o.ajax.runAction("ui.avatar.mask.delete",{data:{id:e},analyticsLabel:{ui:"avatarMask",actionType:"edit",action:"delete"}})}static useRecently(e){return o.ajax.runAction("ui.avatar.mask.useRecently",{data:{id:e},analyticsLabel:{ui:"avatarMask",actionType:"read",action:"read"}})}static cleanUp(){return o.ajax.runAction("ui.avatar.mask.cleanUp",{analyticsLabel:{ui:"avatarMask",actionType:"edit",action:"cleanUp"}})}}Object.defineProperty(y,f,{writable:true,value:{}});let _=e=>e,T;function w(e,t,s){t=t?String(t):null;s=s?Number(s):null;e=String(e).toLowerCase();let a=e.split(".").pop();if(a===e){a=null}return(t===null||t.indexOf("image/")===0)&&(s===null||s<20*1024*1024)&&a!==e&&"jpg,bmp,jpeg,jpe,gif,png,webp".split(",").indexOf(a)>=0}var x=babelHelpers.classPrivateFieldLooseKey("fileId");var k=babelHelpers.classPrivateFieldLooseKey("fileAccept");class A extends P{constructor(e){super();Object.defineProperty(this,x,{writable:true,value:void 0});Object.defineProperty(this,k,{writable:true,value:"image/*"});babelHelpers.classPrivateFieldLooseBase(this,x)[x]=["fileUpload_",(new Date).valueOf()].join("_");if(e&&e.fileAccept){babelHelpers.classPrivateFieldLooseBase(this,k)[k]=e.fileAccept}}getHeader(){return null}getBody(){return this.cache.remember("body",(()=>{const e=o.Tag.render(T||(T=_`
			<div>
				<div class="ui-avatar-editor__btn-back" data-bx-role="button-back"></div>
				<div class="ui-avatar-editor__upload-link-container">
					<div data-bx-role="error-container" class="ui-avatar-editor__upload-error-desc"></div>
					<label for="${0}" class="ui-avatar-editor__upload-link">
						${0}
						<input type="file" id="${0}" data-bx-role="file-button" accept="${0}" />
					</label>
					<div class="ui-avatar-editor__upload-desc">
						${0}
					</div>
				</div>
				<div class="ui-avatar-editor__upload-info">
					<div class="ui-avatar-editor__upload-info-item"><!-- place for limit text --></div>
				</div>
			</div>`),babelHelpers.classPrivateFieldLooseBase(this,x)[x],o.Loc.getMessage("JS_AVATAR_EDITOR_PICK_UP_THE_FILE"),babelHelpers.classPrivateFieldLooseBase(this,x)[x],o.Text.encode(babelHelpers.classPrivateFieldLooseBase(this,k)[k]),o.Loc.getMessage("JS_AVATAR_EDITOR_DROP_FILES_INTO_THIS_AREA"));const t=s=>{const{target:a}=s;const i=e.querySelector('[data-bx-role="file-button"]');const l=Array.from(a&&a.files?a.files:i.files).shift();if(w(l.name,l.type,l.size)){this.emit("onSetFile",l)}o.Event.unbindAll(i);const r=i.cloneNode(true,{value:""});o.Dom.adjust(r,{props:{value:""},attrs:{}});r.setAttribute("new","Y"+(new Date).valueOf());i.parentNode.insertBefore(r,i);i.parentNode.removeChild(i);o.Event.bind(r,"change",t)};o.Event.bind(e.querySelector('[data-bx-role="file-button"]'),"change",t);const s=new BX.DD.dropFiles(e);if(s&&s.supported()){n.EventEmitter.subscribe(s,"dropFiles",((e,s)=>{if(s&&s["dataTransfer"]&&s["dataTransfer"]["items"]&&s["dataTransfer"]["items"].length>0){const t=[];Array.from(s["dataTransfer"]["items"]).forEach((e=>{if(e["webkitGetAsEntry"]&&e["getAsFile"]){let s=e["webkitGetAsEntry"]();if(s&&s.isFile){t.push(e["getAsFile"]())}}}));if(t.length>0){e=t}}t({target:{files:e}})}),{compatMode:true});n.EventEmitter.subscribe(s,"dragEnter",(t=>{if(t&&t["dataTransfer"]&&t.dataTransfer.types&&t.dataTransfer.items){const s=Array.from(t.dataTransfer.types).filter((e=>e==="Files")).length>0;if(s){o.Dom.addClass(e.parentNode,"dnd-over")}}}),{compatMode:true});n.EventEmitter.subscribe(s,"dragLeave",(()=>{o.Dom.removeClass(e.parentNode,"dnd-over")}),{compatMode:true})}e.querySelector('[data-bx-role="button-back"]').onclick=()=>{this.emit("onClickBack")};return e}))}deleteError(){this.getBody().querySelector('[data-bx-role="error-container"]').innerText="";o.Dom.removeClass(this.getBodyContainer(),"ui-avatar-editor--error")}static get code(){return"upload"}}A.priority=3;const C={maskSize:400,imageSize:1024,rawSrc:document.currentScript.src,rawPath:null,eventNamespace:"Main.Avatar.Editor",get path(){if(C.rawPath===null){const e=C.rawSrc.split("/");let t;while(t=e.pop()){if(t==="dist"){break}}C.rawPath=new o.Uri(e.join("/")).getPath()}return C.rawPath},getCollections:()=>{const e=Extension.getSettings("ui.avatar-editor");return Array.from(e["commonCollection"])[{title:"Sys",items:["001_flower.png","002_flower.png","003_christmas_tree256.png","005_red_rectangle.png","005_blue_circle.png","004_bow_purple.png"].map((function(e){return{id:e,title:e,thumb:[C.path,"badges",e].join("/").replace("//","/"),src:[C.path,"badges",e].join("/").replace("//","/")}}))}]}};let I=e=>e,S;var M=babelHelpers.classPrivateFieldLooseKey("instance");var E=babelHelpers.classPrivateFieldLooseKey("data");var O=babelHelpers.classPrivateFieldLooseKey("id");var R=babelHelpers.classPrivateFieldLooseKey("changesCount");var D=babelHelpers.classPrivateFieldLooseKey("getEditor");var j=babelHelpers.classPrivateFieldLooseKey("initAccessSelector");var N=babelHelpers.classPrivateFieldLooseKey("showSlider");var K=babelHelpers.classPrivateFieldLooseKey("subscribedToASliderEvents");class U extends n.EventEmitter{constructor(){super();Object.defineProperty(this,N,{value:q});Object.defineProperty(this,j,{value:z});Object.defineProperty(this,D,{value:$});this.cache=new o.Cache.MemoryCache;Object.defineProperty(this,E,{writable:true,value:void 0});Object.defineProperty(this,O,{writable:true,value:void 0});Object.defineProperty(this,R,{writable:true,value:0});this.setEventNamespace([C.eventNamespace,"mask:editor"].join(":"));babelHelpers.classPrivateFieldLooseBase(this,O)[O]=[this.getEventNamespace(),(new Date).getTime()].join(":")}getContentContainer(){return this.cache.remember("content",(()=>{const e=o.Tag.render(S||(S=I`<div class="ui-avatar-editor--scope">
						<ol class="ui-avatar-editor-list">
							<li class="ui-avatar-editor-list-item">
								<span class="ui-avatar-editor-list-item-num">1</span>
								${0}
								<div class="ui-avatar-editor-list-link-box">
									<a href="${0}" class="ui-avatar-editor-list-link">${0}</a>
									<a href="/bitrix/js/ui/avatar-editor/dist/user_frame_template.zip" download class="ui-avatar-editor-list-link">${0}</a>
								</div>
							</li>
							<li class="ui-avatar-editor-list-item">
								<span class="ui-avatar-editor-list-item-num">2</span>
								${0}
								<div class="ui-avatar-editor-mask-file" data-bx-role="mask-file"></div>
							</li>
							<li class="ui-avatar-editor-list-item">${0}
								<span class="ui-avatar-editor-list-item-num">3</span>
								<div class="ui-form">
									<div class="ui-form-row">
										<div class="ui-form-label">
											<div class="ui-ctl-label-text">${0}</div>
										</div>
										<div class="ui-form-content">
											<div class="ui-ctl ui-ctl-textbox ui-ctl-w100">
												<input data-bx-role="title" type="text" class="ui-ctl-element" placeholder="${0}">
											</div>
										</div>
									</div>
									<div class="ui-form-row">
										<div class="ui-form-label">
											<div class="ui-ctl-label-text">${0}</div>
										</div>
										<div class="ui-form-content">
											<div class="ui-ctl ui-ctl-textbox ui-ctl-w100" data-bx-role="access-container"></div>
										</div>
									</div>
								</div>
							</li>
						</ol>
					</div>`),o.Loc.getMessage("UI_AVATAR_EDITOR_MASK_CREATOR_CONTENT_1_POINT").replace(/#SIZE/gi,o.Loc.getMessage("UI_AVATAR_MASK_MAX_SIZE")),o.Loc.getMessage("UI_AVATAR_MASK_PATH_ARTICLE"),o.Loc.getMessage("JS_AVATAR_EDITOR_HOW_TO"),o.Loc.getMessage("UI_AVATAR_EDITOR_MASK_DOWNLOAD_TEMPLATE2"),o.Loc.getMessage("UI_AVATAR_EDITOR_MASK_CREATOR_CONTENT_2_POINT"),o.Loc.getMessage("UI_AVATAR_EDITOR_MASK_CREATOR_CONTENT_3_POINT"),o.Loc.getMessage("JS_AVATAR_EDITOR_TITLE"),o.Loc.getMessage("JS_AVATAR_EDITOR_PLACEHOLDER"),o.Loc.getMessage("JS_AVATAR_EDITOR_ACCESS"));e.querySelector('[data-bx-role="mask-file"]').appendChild(babelHelpers.classPrivateFieldLooseBase(this,D)[D]().getContainer());babelHelpers.classPrivateFieldLooseBase(this,D)[D]().getCanvasZooming().setDefaultValue(.5).reset();return e}))}isModified(){return babelHelpers.classPrivateFieldLooseBase(this,R)[R]>0}openNew(){babelHelpers.classPrivateFieldLooseBase(this,N)[N]().then((()=>{babelHelpers.classPrivateFieldLooseBase(this,R)[R]=0;babelHelpers.classPrivateFieldLooseBase(this,E)[E]={id:null,title:"",src:null,accessCode:[["meta-user","all-users"]]};babelHelpers.classPrivateFieldLooseBase(this,D)[D]().reset();this.getContentContainer().querySelector('[data-bx-role="title"]').value="";babelHelpers.classPrivateFieldLooseBase(this,j)[j]()}))}openSaved(e){babelHelpers.classPrivateFieldLooseBase(this,E)[E]={id:e.id,title:e.title,src:e.src,accessCode:e.accessCode||null};this.getContentContainer().querySelector('[data-bx-role="title"]').value=o.Text.encode(e.title);babelHelpers.classPrivateFieldLooseBase(this,N)[N]().then((()=>{babelHelpers.classPrivateFieldLooseBase(this,D)[D]().loadSrc(e.src).then((()=>{babelHelpers.classPrivateFieldLooseBase(this,R)[R]=0;if(!e.accessCode){y.getMaskAccessCode(e.id).then((({data:{accessCode:e}})=>{this.emit("maskAccessCodeHasGot",e);babelHelpers.classPrivateFieldLooseBase(this,E)[E].accessCode=e;babelHelpers.classPrivateFieldLooseBase(this,j)[j]()}))}else{babelHelpers.classPrivateFieldLooseBase(this,E)[E].accessCode=Array.from(e.accessCode);babelHelpers.classPrivateFieldLooseBase(this,j)[j]()}}))}))}checkOpened(){return new Promise(((e,t)=>{let s=true;if(babelHelpers.classPrivateFieldLooseBase(this,D)[D]().isEmpty()){babelHelpers.classPrivateFieldLooseBase(this,D)[D]().getTab(A.code).showError({message:o.Loc.getMessage("JS_AVATAR_EDITOR_ERROR_IMAGE_IS_NOT_CHOSEN")});s=false}const a=this.getContentContainer().querySelector('[data-bx-role="title"]').value.trim();if(a.length<=0){this.getContentContainer().querySelector('[data-bx-role="title"]').style.border="3px solid red";s=false}if(s){return e()}return t()}))}saveOpened(){return new Promise(((e,t)=>{const s=({blob:s})=>{y.saveMask({id:babelHelpers.classPrivateFieldLooseBase(this,E)[E].id,title:this.getContentContainer().querySelector('[data-bx-role="title"]').value,accessCode:babelHelpers.classPrivateFieldLooseBase(this,E)[E].accessCode},s).then(e).catch(t)};if(!this.isModified()){return s({blob:null})}return babelHelpers.classPrivateFieldLooseBase(this,D)[D]().packBlob().then(s)}))}destroy(){babelHelpers.classPrivateFieldLooseBase(this,D)[D]().reset();this.getContentContainer().querySelector('[data-bx-role="title"]').value="";babelHelpers.classPrivateFieldLooseBase(this,E)[E]=null;this.cache.storage.clear()}emit(e,t){BX.SidePanel.Instance.postMessageAll(babelHelpers.classPrivateFieldLooseBase(this,O)[O],e,t);return this}static subscribe(e,t){n.EventEmitter.subscribe([C.eventNamespace,"mask:editor",e].join(":"),t);if(babelHelpers.classPrivateFieldLooseBase(this,K)[K]){return}babelHelpers.classPrivateFieldLooseBase(this,K)[K]=true;n.EventEmitter.subscribe("SidePanel.Slider:onMessage",(({data:[e]})=>{if(e.getSender().getUrl().indexOf([C.eventNamespace,"mask:editor"].join(":"))===0){n.EventEmitter.emit([C.eventNamespace,"mask:editor",e.getEventId()].join(":"),e.getData())}}))}static getInstance(){if(babelHelpers.classPrivateFieldLooseBase(this,M)[M]){return babelHelpers.classPrivateFieldLooseBase(this,M)[M]}if(window===window.top){if(!babelHelpers.classPrivateFieldLooseBase(this,M)[M]){babelHelpers.classPrivateFieldLooseBase(this,M)[M]=new this}return babelHelpers.classPrivateFieldLooseBase(this,M)[M]}return null}static getPromiseWithInstance(){if(babelHelpers.classPrivateFieldLooseBase(this,M)[M]||this.getInstance()){return new Promise((e=>{e(babelHelpers.classPrivateFieldLooseBase(this,M)[M])}))}return new Promise((e=>{top.BX.Runtime.loadExtension(["ui.avatar-editor"]).then((()=>{babelHelpers.classPrivateFieldLooseBase(this,M)[M]=top.BX.UI.AvatarEditor.MaskEditor.getInstance();e(babelHelpers.classPrivateFieldLooseBase(this,M)[M])}))}))}}function $(){return this.cache.remember("editor",(()=>{const e=new Rt({enableCamera:false,enableUpload:true,uploadTabOptions:{fileAccept:"image/png"},enableMask:false});e.subscribe("onChange",(({data:e})=>{babelHelpers.classPrivateFieldLooseBase(this,R)[R]++}));return e}))}function z(){return this.cache.remember("TagSelector",(()=>{const e=({target:e})=>{if(e instanceof i.Dialog){babelHelpers.classPrivateFieldLooseBase(this,E)[E].accessCode=e.getSelectedItems().map((e=>[e.entityId,e.id]))}};const t=new top.BX.UI.EntitySelector.TagSelector({id:this.constructor.name,dialogOptions:{id:this.constructor.name,context:null,preselectedItems:babelHelpers.classPrivateFieldLooseBase(this,E)[E].accessCode,events:{"Item:onSelect":e,"Item:onDeselect":e},entities:[{id:"meta-user",options:{"all-users":{title:"All users",allowView:true}}},{id:"user",options:{emailUsers:false,inviteGuestLink:false,myEmailUsers:false}},{id:"department",options:{selectMode:"usersAndDepartments",allowFlatDepartments:false}}]}});t.renderTo(this.getContentContainer().querySelector('[data-bx-role="access-container"]'));return t}))}function q(){return new Promise(((e,t)=>{BX.SidePanel.Instance.open(babelHelpers.classPrivateFieldLooseBase(this,O)[O],{width:800,cacheable:false,allowChangeHistory:false,events:{onCloseByEsc:e=>{e.denyAction()},onOpen:()=>{setTimeout((()=>{this.emit("onOpen",{})}),0);e()},onCloseComplete:this.destroy.bind(this)},contentCallback:e=>b.Layout.createContent({extensions:[],title:o.Loc.getMessage("UI_AVATAR_EDITOR_MASK_CREATOR_TITLE"),content:()=>{const e=this.getContentContainer();setTimeout((()=>{babelHelpers.classPrivateFieldLooseBase(this,D)[D]().getCanvasZooming().setDefaultValue(.5).reset()}),0);return e},buttons:({CancelButton:t,SaveButton:s})=>[new s({onclick:t=>{t.setWaiting(true);this.checkOpened().then(this.saveOpened.bind(this)).then((({data:s})=>{this.emit("onSave",{id:babelHelpers.classPrivateFieldLooseBase(this,E)[E].id,data:s});t.setWaiting(false);e.close()})).catch((e=>{if(e){BX.UI.Notification.Center.notify({content:["Error is here",...arguments].join("-")})}t.setWaiting(false)}))}}),new t({onclick:()=>{e.close()}})]}),label:{text:o.Loc.getMessage("UI_AVATAR_EDITOR_MASK_CREATOR_LABEL")}})}))}Object.defineProperty(U,M,{writable:true,value:void 0});Object.defineProperty(U,K,{writable:true,value:false});let V=e=>e,X;var W=babelHelpers.classPrivateFieldLooseKey("repo");var J=babelHelpers.classPrivateFieldLooseKey("template");class G extends n.EventEmitter{constructor(e,t){super();this.cache=new o.Cache.MemoryCache;Object.defineProperty(this,J,{writable:true,value:void 0});this.setEventNamespace("Main.Avatar.Editor");this.data=e;babelHelpers.classPrivateFieldLooseBase(this,J)[J]=t;U.subscribe("onSave",(e=>{try{const{data:{id:t,data:s}}=e;if(String(this.data.id)===String(t)){this.update(s)}}catch(e){console.log(e.message)}}))}getContainer(){return this.cache.remember("container",(()=>{const e=babelHelpers.classPrivateFieldLooseBase(this,J)[J].replace(/#MASK_ID#/gi,o.Text.encode(this.data.id)).replace(/#MASK_TITLE#/gi,o.Text.encode(this.data.title||"")).replace(/#MASK_SUBTITLE#/gi,o.Text.encode(this.data.description||"")).replace(/#MASK_SRC#/gi,o.Text.encode(this.data.src));const t=o.Tag.render(X||(X=V`${0}`),e);o.Event.bind(t.querySelector('[data-bx-role="mask-item-menu-pointer"]'),"click",this.onClickMenuPointer.bind(this));babelHelpers.classPrivateFieldLooseBase(this.constructor,W)[W].set(t,this);o.Event.bind(t,"click",this.setActive.bind(this));return t}))}getData(){return Object.assign({},this.data)}getId(){return this.data.id}update(e){this.data.title=e.title;this.data.src=e.src;this.data.description=e.description;this.data.accessCode=e.accessCode;this.data.editable=e.editable;const t=this.getContainer();this.cache.delete("container");const s=this.getContainer();o.Dom.replace(t,s)}setActive(){this.emit("onClickMask")}onClickMenuPointer(e){e.preventDefault();e.stopPropagation();const t="mask-item-menu-context-"+this.data.id;const s=c.MenuManager.create(t,e.target,[{href:this.data.src,dataset:{id:"download"},text:o.Loc.getMessage("JS_AVATAR_EDITOR_DOWNLOAD_BUTTON"),onclick:(e,t)=>{t.getMenuWindow().close()}},this.data.editable?{text:o.Loc.getMessage("JS_AVATAR_EDITOR_EDIT_BUTTON"),onclick:(e,t)=>{this.emit("onClickEditMask");t.getMenuWindow().close()}}:null,this.data.editable?{text:o.Loc.getMessage("JS_AVATAR_EDITOR_DELETE_BUTTON"),onclick:(e,t)=>{this.emit("onClickDeleteMask");t.getMenuWindow().close()}}:null],{closeByEsc:true,autoHide:true,offsetTop:0,offsetLeft:15,angle:true,cacheable:false,targetContainer:e.target.closest(".ui-avatar-editor__mask-block-container"),className:"popup-window-content-frame-item-menu",events:{onFirstShow:({compatData:[e]})=>{e.getContentContainer().querySelector('[data-id="download"]').setAttribute("download","")}}});s.show();n.EventEmitter.subscribeOnce(s.getPopupWindow().getEventNamespace()+":onBeforeShow",(()=>{s.close()}));return false}static getByNode(e){return babelHelpers.classPrivateFieldLooseBase(this,W)[W].get(e)}}Object.defineProperty(G,W,{writable:true,value:new WeakMap});let Y=e=>e,Z,Q,ee,te,se,ae;var ie=babelHelpers.classPrivateFieldLooseKey("container");var le=babelHelpers.classPrivateFieldLooseKey("state");var re=babelHelpers.classPrivateFieldLooseKey("pageSize");var oe=babelHelpers.classPrivateFieldLooseKey("pageNumber");var ne=babelHelpers.classPrivateFieldLooseKey("getTemplateGroup");var ce=babelHelpers.classPrivateFieldLooseKey("getTemplateItem");class de extends n.EventEmitter{constructor({initialPageSize:e,items:t}){super();Object.defineProperty(this,ce,{value:he});Object.defineProperty(this,ne,{value:be});Object.defineProperty(this,ie,{writable:true,value:void 0});this.cache=new o.Cache.MemoryCache;Object.defineProperty(this,le,{writable:true,value:this.constructor.paginationStates["ready"]});Object.defineProperty(this,re,{writable:true,value:10});Object.defineProperty(this,oe,{writable:true,value:1});this.setEventNamespace("Main.Avatar.Editor");babelHelpers.classPrivateFieldLooseBase(this,ie)[ie]=this.getContainer().querySelector('[data-bx-role="avatar-mask-list-container"]');babelHelpers.classPrivateFieldLooseBase(this,re)[re]=this.constructor.regularPageSize;this.loadItems(t);this.setReady()}static getTemplate(){return`<div>\n\t\t\t\t<div class="ui-avatar-editor--scope" data-bx-role="avatar-mask-list-container">\n\t\t\t\t\t<section class="ui-avatar-editor__mask-block-list-container" id="mask_group">\n\t\t\t\t\t\t<h3 class="ui-avatar-editor__mask-title" data-bx-role="group_title" data-bx-group-id="#GROUP_ID#">#GROUP_TITLE#</h3>\n\t\t\t\t\t\t<ul class="ui-avatar-editor__mask-block-mask-box" data-bx-role="group_body" data-bx-group-id="#GROUP_ID#">\n\t\t\t\t\t\t\t<li class="ui-avatar-editor__mask-block-mask-element" \n\t\t\t\t\t\t\t\tid="mask_item"\n\t\t\t\t\t\t\t\tdata-bx-role="mask_item"\n\t\t\t\t\t\t\t\ttitle="#MASK_TITLE# \n #MASK_SUBTITLE#"\n\t\t\t\t\t\t\t\tdata-bx-id="#MASK_ID#">\n\t\t\t\t\t\t\t\t<div data-bx-role="mask-thumb" class="ui-avatar-editor__mask-block-mask-image" style="background-image: url('#MASK_SRC#'); "/></div>\n\t\t\t\t\t\t\t\t<div class="ui-avatar-editor__mask-block-mask-name">#MASK_TITLE#</div>\n\t\t\t\t\t\t\t\t<div class="ui-avatar-editor__mask-block-mask-subname">#MASK_SUBTITLE#</div>\n\t\t\t\t\t\t\t\t<div class="ui-avatar-editor__mask-block-mask-menu" data-bx-role="mask-item-menu-pointer"></div>\n\t\t\t\t\t\t\t</li>\n\t\t\t\t\t\t</ul>\n\t\t\t\t\t</section>\n\t\t\t\t</div>\n\t\t\t\t<nav class="ui-avatar-editor-pagination" data-bx-role="avatar-mask-list-pagination"></nav>\n\t\t\t</div>`}static setByNode(e,t){return this.repoList.set(e,t)}static getByNode(e){return this.repoList.get(e)}setPageSize(e){babelHelpers.classPrivateFieldLooseBase(this,re)[re]=e;return this}getContainer(){return this.cache.remember("container",(()=>{const e=o.Tag.render(Z||(Z=Y`${0}`),this.constructor.getTemplate());o.Dom.remove(e.querySelector("#mask_item"));o.Dom.remove(e.querySelector("#mask_group"));return e}))}isReady(){return babelHelpers.classPrivateFieldLooseBase(this,le)[le]===this.constructor.paginationStates.ready}setReady(){this.getMoreButton().setWaiting(false);babelHelpers.classPrivateFieldLooseBase(this,le)[le]=this.constructor.paginationStates.ready}setBusy(){this.getMoreButton().setWaiting(true);babelHelpers.classPrivateFieldLooseBase(this,le)[le]=this.constructor.paginationStates.inprogress}setFinished(){this.getMoreButton().setDisabled(true);babelHelpers.classPrivateFieldLooseBase(this,le)[le]=this.constructor.paginationStates.finished;o.Dom.remove(this.getContainer().querySelector('[data-bx-role="avatar-mask-list-pagination"]'))}getMoreButton(){return this.cache.remember("moreButton",(()=>{const e=new d.Button({text:o.Loc.getMessage("UI_AVATAR_EDITOR_MASK_LIST_PAGINATION"),baseClass:"ui-btn ui-btn-light-border",size:d.ButtonSize.SMALL,noCaps:true,round:true,onclick:this.load.bind(this)});e.renderTo(this.getContainer().querySelector('[data-bx-role="avatar-mask-list-pagination"]'));return e}))}load(){if(!this.isReady()){return}this.setBusy();y.getMaskList(this.constructor.name.replace("Mask",""),{page:++babelHelpers.classPrivateFieldLooseBase(this,oe)[oe],size:babelHelpers.classPrivateFieldLooseBase(this,re)[re]}).then(this.loadItems.bind(this)).catch(this.terminate.bind(this))}loadItems(e){this.renderItems(e);this.finish(e)}renderItems(e){let t=babelHelpers.classPrivateFieldLooseBase(this,re)[re];Object.values(e).forEach((({id:e,title:s,items:a})=>{if(t<=0){return}a=Object.values(a).slice(0,t);t-=a.length;e=e||"0";if(!babelHelpers.classPrivateFieldLooseBase(this,ie)[ie].querySelector(`[data-bx-group-id="${e}"][data-bx-role="group_body"]`)){const t=babelHelpers.classPrivateFieldLooseBase(this,ne)[ne]().replace(/#GROUP_ID#/gi,o.Text.encode(e)).replace(/#GROUP_TITLE#/gi,o.Text.encode(s||""));babelHelpers.classPrivateFieldLooseBase(this,ie)[ie].appendChild(o.Tag.render(Q||(Q=Y`${0}`),t))}const i=babelHelpers.classPrivateFieldLooseBase(this,ie)[ie].querySelector(`[data-bx-group-id="${e}"][data-bx-role="group_body"]`);a.forEach((e=>{const t=new G(e,babelHelpers.classPrivateFieldLooseBase(this,ce)[ce]());i.appendChild(t.getContainer())}))}))}renderItemsReverse(e){Object.values(e).forEach((({id:e,title:t,items:s})=>{e=e||"0";if(!babelHelpers.classPrivateFieldLooseBase(this,ie)[ie].querySelector(`[data-bx-group-id="${e}"][data-bx-role="group_body"]`)){const s=babelHelpers.classPrivateFieldLooseBase(this,ne)[ne]().replace(/#GROUP_ID#/gi,o.Text.encode(e)).replace(/#GROUP_TITLE#/gi,o.Text.encode(t||""));o.Dom.prepend(o.Tag.render(ee||(ee=Y`${0}`),s),babelHelpers.classPrivateFieldLooseBase(this,ie)[ie])}const a=babelHelpers.classPrivateFieldLooseBase(this,ie)[ie].querySelector(`[data-bx-group-id="${e}"][data-bx-role="group_body"]`);s.forEach((e=>{const t=new G(e,babelHelpers.classPrivateFieldLooseBase(this,ce)[ce]());o.Dom.prepend(t.getContainer(),a)}))}))}finish(e){let t=0;e.forEach((({items:e})=>{t+=e.length}));if(t>=babelHelpers.classPrivateFieldLooseBase(this,re)[re]){this.setReady()}else{this.setFinished()}}terminate(e){let t=[];if(e instanceof Error){console.log("data: ",e);t.push(e)}else if(e["errors"]){t=e.errors}else{t.push({message:"Some error"})}this.setFinished();t.forEach((({code:e,message:t})=>{babelHelpers.classPrivateFieldLooseBase(this,ie)[ie].appendChild(o.Tag.render(te||(te=Y`<pre>${0}</pre>`),o.Text.encode(t)))}))}}function be(){return this.cache.remember("templateGroup",(()=>{const e=o.Tag.render(se||(se=Y`${0}`),this.constructor.getTemplate()).querySelector("#mask_group");const t=e.querySelector("#mask_item");t.parentNode.removeChild(t);e.removeAttribute("id");return e.outerHTML.trim()}))}function he(){return this.cache.remember("templateItem",(()=>{const e=o.Tag.render(ae||(ae=Y`${0}`),this.constructor.getTemplate()).querySelector("#mask_item");e.removeAttribute("id");return e.outerHTML.trim()}))}de.repoList=new WeakMap;de.paginationStates={ready:0,inprogress:1,finished:3};de.regularPageSize=9;de.shortPageSize=3;class ve extends de{}class pe extends de{}class ue extends de{constructor(){super(...arguments);U.subscribe("onSave",(e=>{try{const{data:{id:t,data:s}}=e;if(t===null){this.renderItemsReverse({doesNotMatter:{items:[s]}})}}catch(e){console.log(e.message)}}))}}class me extends de{}let ge=e=>e,Pe;var Le=babelHelpers.classPrivateFieldLooseKey("ready");var Be=babelHelpers.classPrivateFieldLooseKey("callbacks");var Fe=babelHelpers.classPrivateFieldLooseKey("fulfillReadyCallbacksTimeout");var He=babelHelpers.classPrivateFieldLooseKey("deleteMaskVisually");class fe extends P{constructor(){super();Object.defineProperty(this,He,{value:ye});Object.defineProperty(this,Le,{writable:true,value:false});Object.defineProperty(this,Be,{writable:true,value:[]});Object.defineProperty(this,Fe,{writable:true,value:void 0});this.badges=null;this.activeId=null;this.mask=this.mask.bind(this);this.subscribeOnce("onActive",this.initialize.bind(this))}getHeader(){return o.Loc.getMessage("JS_AVATAR_EDITOR_MASKS")}getBody(){return this.cache.remember("body",(()=>o.Tag.render(Pe||(Pe=ge`<div class="ui-avatar-editor__mask-block-container">
				<div class="ui-avatar-editor__mask-block-content">
					<div data-bx-role="semantic-container" data-bx-id="recently-used" style="display: none;">
						<h3 class="ui-avatar-editor__mask-title">${0}</h3>
						<div data-bx-role="list-container" data-bx-id="recently-used"></div>
					</div>
					<div data-bx-role="list-container" data-bx-id="system"></div>
					<div data-bx-role="semantic-container" data-bx-id="shared" style="display: none">
						<h3 class="ui-avatar-editor__mask-title">${0}</h3>
						<div data-bx-role="list-container" data-bx-id="shared">
							<a class="ui-btn ui-btn-lg ui-btn-link ui-btn-wait ui-btn-no-caps ui-btn-icon-add">...</a>
						</div>
					</div>
					<div data-bx-role="semantic-container" data-bx-id="my-own">
						<h3 class="ui-avatar-editor__mask-title" data-bx-id="rest-market-export-menu">
							${0}
							<div data-bx-id="rest-market-export-menu-pointer" class="ui-avatar-editor__menu-more"></div>
						</h3>
						<div data-bx-role="list-container" data-bx-id="my-own"></div>

						<a href="#" class="ui-avatar-editor__mask-create-box" data-bx-role="semantic-container" data-bx-id="rest-market" style="display: none;">
							<div class="ui-avatar-editor__mask-btn-load">
								<div class="ui-avatar-editor__mask-btn-load-icon"></div>
								${0}
								<div class="ui-avatar-editor__mask-btn-load-cloud"></div>
							</div>
						</a>

						<div class="ui-avatar-editor__mask-create-box">
							<div class="ui-avatar-editor__mask-btn-add" data-bx-id="avatar-mask-list-own-create">${0}</div>
							<a href="/bitrix/js/ui/avatar-editor/dist/user_frame_template.zip" download class="ui-avatar-editor__mask-link">${0}</a>
						</div>
					</div>
				</div>
			</div>`),o.Loc.getMessage("JS_AVATAR_EDITOR_RECENT_MASKS"),o.Loc.getMessage("UI_AVATAR_EDITOR_MASK_LIST_SHARED"),o.Loc.getMessage("UI_AVATAR_EDITOR_MASK_LIST_MY_OWN"),o.Loc.getMessage("JS_AVATAR_EDITOR_LOAD_FROM_MARKET"),o.Loc.getMessage("UI_AVATAR_EDITOR_MASK_ADD_MY_OWN"),o.Loc.getMessage("UI_AVATAR_EDITOR_MASK_DOWNLOAD_TEMPLATE1"))))}initialize(){y.getMaskInitialInfo({size:de.regularPageSize,recentlyUsedListSize:de.shortPageSize}).then(this.initializeData.bind(this)).catch((e=>{console.log("errors: ",e)}))}initializeData({recentlyUsedItems:e,systemItems:t,myOwnItems:s,sharedItems:a,restMarketInfo:i}){const l=this.getBody();if(o.Loc.getMessage("USER_ID")>0){o.Event.bind(l.querySelector('[data-bx-id="avatar-mask-list-own-create"]'),"click",this.onClickCreateMask.bind(this));n.EventEmitter.subscribe(this.getEventNamespace()+":"+"onClickEditMask",this.onClickEditMask.bind(this));n.EventEmitter.subscribe(this.getEventNamespace()+":"+"onClickDeleteMask",this.onClickDeleteMask.bind(this))}if(i["available"]==="Y"){const e=l.querySelector('[data-bx-id="rest-market-export-menu"]');o.Dom.addClass(e,"--menuable");o.Event.bind(e.querySelector('[data-bx-id="rest-market-export-menu-pointer"]'),"click",(e=>{this.onClickOwnMaskMenu(e,i)}));const t=l.querySelector('[data-bx-role="semantic-container"][data-bx-id="rest-market"]');t.style.display="";t.href=i["marketUrl"]}[[ve,e,l.querySelector('[data-bx-role="list-container"][data-bx-id="recently-used"]')],[pe,t,l.querySelector('[data-bx-role="list-container"][data-bx-id="system"]')],[ue,s,l.querySelector('[data-bx-role="list-container"][data-bx-id="my-own"]')],[me,a,l.querySelector('[data-bx-role="list-container"][data-bx-id="shared"]')]].forEach((([e,t,s])=>{t=t||[];if(t.length>0){const e=s.closest('[data-bx-role="semantic-container"]');if(e){e.style.display=""}}s.innerHTML="";const a=new e({initialPageSize:this.constructor.initialPageSize,items:t});s.appendChild(a.getContainer());de.setByNode(s,a)}));n.EventEmitter.subscribe(this.getEventNamespace()+":"+"onClickMask",(({target:e})=>{if(this.getBody().contains(e.getContainer())){if(this.activeId===e.getId()){this.unmask()}else{this.mask(e.getData())}}}));babelHelpers.classPrivateFieldLooseBase(this,Le)[Le]=true;this.fulfillReadyCallbacks()}onReady(e){babelHelpers.classPrivateFieldLooseBase(this,Be)[Be].push(e);if(babelHelpers.classPrivateFieldLooseBase(this,Le)[Le]){this.fulfillReadyCallbacks()}}fulfillReadyCallbacks(){if(babelHelpers.classPrivateFieldLooseBase(this,Fe)[Fe]>0){return}const e=babelHelpers.classPrivateFieldLooseBase(this,Be)[Be].shift();if(e){if(babelHelpers.classPrivateFieldLooseBase(this,Be)[Be].length>0){babelHelpers.classPrivateFieldLooseBase(this,Fe)[Fe]=setTimeout((()=>{babelHelpers.classPrivateFieldLooseBase(this,Fe)[Fe]=0;this.fulfillReadyCallbacks()}),10)}e.call(this)}}unmask(){if(this.activeId!==null){let e;this.getBody().querySelectorAll(`[data-bx-role="mask_item"][data-bx-id="${this.activeId}"]`).forEach((t=>{e=t;o.Dom.removeClass(t,"--active")}));if(e){this.emit("onUnsetMask",this.activeId)}}this.activeId=null}maskById(e){this.onReady((()=>{const t=G.getByNode(this.getBody().querySelector(`[data-bx-role="mask_item"][data-bx-id="${e}"]`));if(t instanceof G){t.setActive()}}))}mask({id:e,src:t,thumb:s}){if(this.activeId!==e&&o.Type.isStringFilled(e)){this.unmask();let a;this.getBody().querySelectorAll(`[data-bx-role="mask_item"][data-bx-id="${e}"]`).forEach((e=>{a=e;o.Dom.addClass(e," --active")}));if(a){this.activeId=e;this.emit("onSetMask",{id:e,src:t,thumb:s||t})}}}onClickCreateMask(e){e.stopImmediatePropagation();U.getPromiseWithInstance().then((e=>{e.openNew()}))}onClickEditMask(e){const t=e.getTarget();if(this.getBody().contains(t.getContainer())){e.stopImmediatePropagation();U.getPromiseWithInstance().then((e=>{e.openSaved(Object.assign({},t.getData()))}))}}onClickDeleteMask({target:e}){if(this.getBody().contains(e.getContainer())){babelHelpers.classPrivateFieldLooseBase(this,He)[He](e);y.deleteMask(e.getId()).then((()=>{this.getBody().querySelectorAll(`[data-bx-role="mask_item"][data-bx-id="${e.getId()}"]`).forEach((e=>{o.Dom.remove(e)}))})).catch((({errors:e})=>{BX.UI.Notification.Center.notify({content:[o.Loc.getMessage("JS_AVATAR_EDITOR_ERROR"),...e.map((({message:e,code:t})=>e||t))].join(" ")})}))}}onClickOwnMaskMenu(e,t){const s="mask-item-menu-context-own-masks";const a=!!this.getBody().querySelector('[data-bx-role="list-container"][data-bx-id="my-own"]').querySelector(`[data-bx-role="mask_item"]`);const i=c.MenuManager.create(s,e.target,[a&&o.Type.isStringFilled(t.exportUrl)?{href:t.exportUrl,text:o.Loc.getMessage("JS_AVATAR_EDITOR_EXPORT_BUTTON"),onclick:(e,t)=>{this.emit("onClickExport");t.getMenuWindow().close()}}:null,a?{text:o.Loc.getMessage("JS_AVATAR_EDITOR_CLEAN_BUTTON"),onclick:(e,t)=>{t.getMenuWindow().close();new l.MessageBox({message:o.Loc.getMessage("JS_AVATAR_EDITOR_CLEAN_NOTIFICATION"),title:o.Loc.getMessage("JS_AVATAR_EDITOR_CLEAN_NOTIFICATION_TITLE"),buttons:l.MessageBoxButtons.OK_CANCEL,okCaption:"Ok",onOk:e=>{e.close();this.cleanUp()}}).show()}}:null,{href:t.importUrl,text:o.Loc.getMessage("JS_AVATAR_EDITOR_IMPORT_BUTTON"),onclick:(e,t)=>{this.emit("onClickImport");t.getMenuWindow().close()}}],{closeByEsc:true,autoHide:true,offsetTop:0,offsetLeft:15,angle:true,cacheable:false,targetContainer:e.target.closest(".ui-avatar-editor__mask-block-container"),className:"popup-window-content-frame-item-menu"});i.show();n.EventEmitter.subscribeOnce(i.getPopupWindow().getEventNamespace()+":onBeforeShow",(()=>{i.close()}));return false}cleanUp(){const e=this.getBody().querySelector('[data-bx-role="list-container"][data-bx-id="my-own"]');const t=new r.Loader({target:e,color:"rgba(82, 92, 105, 0.9)"});t.show();y.cleanUp().then((()=>{de.getByNode(e).setFinished();e.querySelectorAll(`[data-bx-role="mask_item"]`).forEach((e=>{babelHelpers.classPrivateFieldLooseBase(this,He)[He](G.getByNode(e))}));t.hide()}))}static isAvailable(){return o.Loc.getMessage("UI_AVATAR_MASK_IS_AVAILABLE")===true}static get code(){return"mask"}}function ye(e){this.getBody().querySelectorAll(`[data-bx-role="mask_item"][data-bx-id="${e.getId()}"]`).forEach((e=>{o.Dom.remove(e)}));const t=this.getBodyContainer().querySelector('[data-bx-role="list-container"][data-bx-id="recently-used"]');if(t.childNodes.length<=1){const e=t.closest('[data-bx-role="semantic-container"]');if(e){e.style.display="none"}}if(String(this.activeId)===String(e.getId())){this.unmask()}}fe.maxCount=5;fe.priority=4;let _e=e=>e,Te;class we extends P{getHeader(){return o.Loc.getMessage("JS_AVATAR_EDITOR_PHOTO")}getBody(){return this.cache.remember("body",(()=>{const e=o.Tag.render(Te||(Te=_e`
				<div class="ui-avatar-editor__content-block" data-bx-role="tab-canvas-body">
					<div class="ui-avatar-editor__control" data-bx-role="canvas-zooming">
						<div class="ui-avatar-editor__control-controller" data-bx-role="zoom-minus-button">
							<span class="ui-avatar-editor__control-minus"></span>
						</div>
						<div class="ui-avatar-editor__control-inner" data-bx-role="zoom-scale">
							<div class="ui-avatar-editor__control-slide-container ui-avatar-editor__control-slide-drag-state">
								<div class="ui-avatar-editor__control-slide" data-bx-role="zoom-knob"></div>
							</div>
						</div>
						<div class="ui-avatar-editor__control-controller" data-bx-role="zoom-plus-button">
							<span class="ui-avatar-editor__control-plus"></span>
						</div>
					</div>
					<div class="ui-avatar-editor__camera-block-image">
						<div class="ui-avatar-editor__user-loader-item" data-bx-role="canvas-loader">
							<div class="ui-avatar-editor__loader">
								<svg class="ui-avatar-editor__circular" viewBox="25 25 50 50">
									<circle class="ui-avatar-editor__path" cx="50" cy="50" r="20" fill="none" stroke-width="1" stroke-miterlimit="10"></circle>
								</svg>
							</div>
						</div>
						<div class="ui-avatar-editor__error" data-bx-role="canvas-error">
							<span>${0}</span>
							<span data-bx-role="tab-canvas-error"></span>
						</div>
						<div class="ui-avatar-editor__user-avatar-item" data-bx-role="canvas-holder">
							<span class="ui-avatar-editor__tab-avatar-image-item"></span>
						</div>

						<div data-editor-role="canvas-holder">
							<canvas data-bx-canvas="canvas" height="330" width="330"></canvas>
						</div>
					</div>
					<div class="ui-avatar-editor__button-layout">
						<div class="ui-avatar-editor__button" data-bx-role="button-add-picture" data-bx-id="upload-file">
							<span class="ui-avatar-editor__button-name">${0}</span>
						</div>
						<div class="ui-avatar-editor__button"  data-bx-role="button-add-picture" data-bx-id="snap-picture">
							<span class="ui-avatar-editor__button-name">${0}</span>
						</div>
					</div>
				</div>`),o.Loc.getMessage("JS_AVATAR_EDITOR_ERROR"),o.Loc.getMessage("JS_AVATAR_EDITOR_UPLOAD"),o.Loc.getMessage("JS_AVATAR_EDITOR_SNAP"));return e}))}static get code(){return"canvas"}}we.priority=1;let xe=e=>e,ke;var Ae=babelHelpers.classPrivateFieldLooseKey("justACounter");var Ce=babelHelpers.classPrivateFieldLooseKey("queue");var Ie=babelHelpers.classPrivateFieldLooseKey("image");var Se=babelHelpers.classPrivateFieldLooseKey("canvas");var Me=babelHelpers.classPrivateFieldLooseKey("context");var Ee=babelHelpers.classPrivateFieldLooseKey("reader");var Oe=babelHelpers.classPrivateFieldLooseKey("isReady");var Re=babelHelpers.classPrivateFieldLooseKey("id");var De=babelHelpers.classPrivateFieldLooseKey("load");var je=babelHelpers.classPrivateFieldLooseKey("exec");var Ne=babelHelpers.classPrivateFieldLooseKey("dataURLToBlob");class Ke{constructor(){Object.defineProperty(this,je,{value:$e});Object.defineProperty(this,De,{value:Ue});Object.defineProperty(this,Ae,{writable:true,value:0});Object.defineProperty(this,Ce,{writable:true,value:void 0});Object.defineProperty(this,Ie,{writable:true,value:void 0});Object.defineProperty(this,Se,{writable:true,value:void 0});Object.defineProperty(this,Me,{writable:true,value:void 0});Object.defineProperty(this,Ee,{writable:true,value:void 0});Object.defineProperty(this,Oe,{writable:true,value:true});Object.defineProperty(this,Re,{writable:true,value:void 0});babelHelpers.classPrivateFieldLooseBase(this,Ee)[Ee]=new FileReader;babelHelpers.classPrivateFieldLooseBase(this,Ce)[Ce]=new Map;babelHelpers.classPrivateFieldLooseBase(this,Ie)[Ie]=new Image;babelHelpers.classPrivateFieldLooseBase(this,Se)[Se]=o.Tag.render(ke||(ke=xe`<canvas id="loadercanvas"></canvas>`));babelHelpers.classPrivateFieldLooseBase(this,Me)[Me]=babelHelpers.classPrivateFieldLooseBase(this,Se)[Se].getContext("2d");babelHelpers.classPrivateFieldLooseBase(this,Re)[Re]=String((new Date).getTime())}push(e,t,s){const a=[babelHelpers.classPrivateFieldLooseBase(this,Re)[Re],babelHelpers.classPrivateFieldLooseBase(this,Ae)[Ae]++].join("_");babelHelpers.classPrivateFieldLooseBase(this,Ce)[Ce].set(a,[e,t,s]);babelHelpers.classPrivateFieldLooseBase(this,je)[je]()}getCanvas(){return babelHelpers.classPrivateFieldLooseBase(this,Se)[Se]}getContext(){return babelHelpers.classPrivateFieldLooseBase(this,Me)[Me]}pack(e){return new Promise(((t,s)=>{try{if(babelHelpers.classPrivateFieldLooseBase(this,Se)[Se]["toBlob"]){babelHelpers.classPrivateFieldLooseBase(this,Se)[Se].toBlob(t,e)}else{t(babelHelpers.classPrivateFieldLooseBase(this.constructor,Ne)[Ne](babelHelpers.classPrivateFieldLooseBase(this,Se)[Se].toDataURL(e)))}}catch(e){e.message="Packing error: "+e.message;s(e)}}))}static getInstance(){if(this.instance===null){this.instance=new this}return this.instance}static loadFile(e,t,s){if(!window["FileReader"]){return s(new Error({message:"FileReader is not supported."}))}let a=e;if(o.Type.isString(e)){a={src:e,name:e.split("/").pop()}}this.getInstance().push(a,t,s)}static loadCanvas(){this.getInstance().getCanvas()}}function Ue(e){if(!babelHelpers.classPrivateFieldLooseBase(this,Ce)[Ce].has(e)||babelHelpers.classPrivateFieldLooseBase(this,Oe)[Oe]!==true){return}babelHelpers.classPrivateFieldLooseBase(this,Oe)[Oe]=false;const[t,s,a]=babelHelpers.classPrivateFieldLooseBase(this,Ce)[Ce].get(e);babelHelpers.classPrivateFieldLooseBase(this,Ie)[Ie].onload=function(){};babelHelpers.classPrivateFieldLooseBase(this,Ie)[Ie].onerror=function(){};try{window["URL"]["revokeObjectURL"](babelHelpers.classPrivateFieldLooseBase(this,Ie)[Ie].src)}catch(e){}if(!o.Browser.isFirefox()){babelHelpers.classPrivateFieldLooseBase(this,Ie)[Ie].src="/bitrix/images/1.gif"}const i=()=>{babelHelpers.classPrivateFieldLooseBase(this,Ce)[Ce].delete(e);babelHelpers.classPrivateFieldLooseBase(this,Oe)[Oe]=true;setTimeout((()=>{babelHelpers.classPrivateFieldLooseBase(this,je)[je]()}),0)};const l=e=>{const t=e&&e.target?e.target:babelHelpers.classPrivateFieldLooseBase(this,Ie)[Ie];if(t.src.indexOf("/bitrix/images/1.gif")>=0){return}if(!!s){i();s(t)}};const r=()=>{if(!!a){try{a()}catch(e){o.Runtime.debug(e)}}i()};babelHelpers.classPrivateFieldLooseBase(this,Ie)[Ie].name=t.name;babelHelpers.classPrivateFieldLooseBase(this,Ie)[Ie].onload=l;babelHelpers.classPrivateFieldLooseBase(this,Ie)[Ie].onerror=r;if(o.Type.isPlainObject(t)&&(t["src"]||t["tmp_url"])){const e=t["src"]||t["tmp_url"];babelHelpers.classPrivateFieldLooseBase(this,Ie)[Ie].src=encodeURI(e)+(e.indexOf("?")>0?"&":"?")+"imageUploader"+babelHelpers.classPrivateFieldLooseBase(this,Re)[Re]+babelHelpers.classPrivateFieldLooseBase(this,Ae)[Ae]++}else{const e=Object.prototype.toString.call(t);if(e!=="[object File]"&&e!=="[object Blob]"){r()}else if(window["URL"]){babelHelpers.classPrivateFieldLooseBase(this,Ie)[Ie].src=window["URL"]["createObjectURL"](t)}else{babelHelpers.classPrivateFieldLooseBase(this,Ee)[Ee].onloadend=e=>{babelHelpers.classPrivateFieldLooseBase(this,Ee)[Ee].onloadend=null;babelHelpers.classPrivateFieldLooseBase(this,Ee)[Ee].onerror=null;babelHelpers.classPrivateFieldLooseBase(this,Ie)[Ie].src=e.target.result};babelHelpers.classPrivateFieldLooseBase(this,Ee)[Ee].onerror=()=>{babelHelpers.classPrivateFieldLooseBase(this,Ee)[Ee].onloadend=null;babelHelpers.classPrivateFieldLooseBase(this,Ee)[Ee].onerror=null;r()};babelHelpers.classPrivateFieldLooseBase(this,Ee)[Ee].readAsDataURL(t)}}}function $e(){if(babelHelpers.classPrivateFieldLooseBase(this,Oe)[Oe]===true){const e=Array.from(babelHelpers.classPrivateFieldLooseBase(this,Ce)[Ce].keys()).shift();if(e){babelHelpers.classPrivateFieldLooseBase(this,De)[De](e)}}}function ze(e){let t=";base64,",s,a,i,l;if(e.indexOf(t)<0){s=e.split(",");a=s[0].split(":")[1];i=s[1];return new Blob([i],{type:a})}s=e.split(t);a=s[0].split(":")[1];i=window.atob(s[1]);l=i.length;const r=new Uint8Array(l);for(let e=0;e<l;++e){r[e]=i.charCodeAt(e)}return new Blob([r],{type:a})}Object.defineProperty(Ke,Ne,{value:ze});Ke.instance=null;var qe=babelHelpers.classPrivateFieldLooseKey("isSet");var Ve=babelHelpers.classPrivateFieldLooseKey("canvas");var Xe=babelHelpers.classPrivateFieldLooseKey("ctx");var We=babelHelpers.classPrivateFieldLooseKey("table");var Je=babelHelpers.classPrivateFieldLooseKey("tableCloth");var Ge=babelHelpers.classPrivateFieldLooseKey("tableFrame");var Ye=babelHelpers.classPrivateFieldLooseKey("stretchToCanvasSize");class Ze extends n.EventEmitter{constructor(e,t){super();Object.defineProperty(this,qe,{writable:true,value:false});Object.defineProperty(this,Ve,{writable:true,value:void 0});Object.defineProperty(this,Xe,{writable:true,value:void 0});Object.defineProperty(this,We,{writable:true,value:void 0});Object.defineProperty(this,Je,{writable:true,value:void 0});Object.defineProperty(this,Ge,{writable:true,value:void 0});Object.defineProperty(this,Ye,{writable:true,value:true});this.setEventNamespace("Main.Avatar.Editor");babelHelpers.classPrivateFieldLooseBase(this,Ve)[Ve]=e;babelHelpers.classPrivateFieldLooseBase(this,Xe)[Xe]=babelHelpers.classPrivateFieldLooseBase(this,Ve)[Ve].getContext("2d");babelHelpers.classPrivateFieldLooseBase(this,We)[We]=babelHelpers.classPrivateFieldLooseBase(this,Ve)[Ve].parentNode;if(babelHelpers.classPrivateFieldLooseBase(this,Ve)[Ve].clientWidth){babelHelpers.classPrivateFieldLooseBase(this,We)[We].width=babelHelpers.classPrivateFieldLooseBase(this,Ve)[Ve].clientWidth;babelHelpers.classPrivateFieldLooseBase(this,We)[We].height=babelHelpers.classPrivateFieldLooseBase(this,Ve)[Ve].clientHeight}else{babelHelpers.classPrivateFieldLooseBase(this,We)[We].width=babelHelpers.classPrivateFieldLooseBase(this,Ve)[Ve].width;babelHelpers.classPrivateFieldLooseBase(this,We)[We].height=babelHelpers.classPrivateFieldLooseBase(this,Ve)[Ve].height}o.Dom.adjust(babelHelpers.classPrivateFieldLooseBase(this,Ve)[Ve],{style:{}});o.Dom.adjust(babelHelpers.classPrivateFieldLooseBase(this,We)[We],{style:{width:`${babelHelpers.classPrivateFieldLooseBase(this,We)[We].width}px`,height:`${babelHelpers.classPrivateFieldLooseBase(this,We)[We].height}px`,border:"none",position:"relative",overflow:"visible"},dataset:{role:"table",width:babelHelpers.classPrivateFieldLooseBase(this,We)[We].width,height:babelHelpers.classPrivateFieldLooseBase(this,We)[We].height}});babelHelpers.classPrivateFieldLooseBase(this,Je)[Je]=o.Dom.create("DIV");o.Dom.adjust(babelHelpers.classPrivateFieldLooseBase(this,Je)[Je],{style:{border:"none",position:"absolute",display:"flex","align-items":"center","justify-content":"center",width:`${babelHelpers.classPrivateFieldLooseBase(this,We)[We].width}px`,height:`${babelHelpers.classPrivateFieldLooseBase(this,We)[We].height}px`,left:0,top:0},dataset:{role:"tableCloth"}});babelHelpers.classPrivateFieldLooseBase(this,Je)[Je].appendChild(babelHelpers.classPrivateFieldLooseBase(this,Ve)[Ve]);babelHelpers.classPrivateFieldLooseBase(this,We)[We].appendChild(babelHelpers.classPrivateFieldLooseBase(this,Je)[Je]);babelHelpers.classPrivateFieldLooseBase(this,Ge)[Ge]=o.Dom.create("DIV");o.Dom.adjust(babelHelpers.classPrivateFieldLooseBase(this,Ge)[Ge],{style:{"box-sizing":"border-box",position:"absolute",width:`${babelHelpers.classPrivateFieldLooseBase(this,We)[We].width}px`,height:`${babelHelpers.classPrivateFieldLooseBase(this,We)[We].height}px`},dataset:{role:"tableFrame"}});babelHelpers.classPrivateFieldLooseBase(this,Je)[Je].appendChild(babelHelpers.classPrivateFieldLooseBase(this,Ge)[Ge]);this.mouseMove=this.mouseMove.bind(this);this.stopMoving=this.stopMoving.bind(this);babelHelpers.classPrivateFieldLooseBase(this,Ye)[Ye]=!(t&&t.stretchToCanvasSize===false);this.reset()}isEmpty(){return!babelHelpers.classPrivateFieldLooseBase(this,qe)[qe]}reset(){babelHelpers.classPrivateFieldLooseBase(this,Xe)[Xe].clearRect(0,0,babelHelpers.classPrivateFieldLooseBase(this,Ve)[Ve].width,babelHelpers.classPrivateFieldLooseBase(this,Ve)[Ve].height);babelHelpers.classPrivateFieldLooseBase(this,qe)[qe]=false;o.Dom.adjust(babelHelpers.classPrivateFieldLooseBase(this,Je)[Je],{style:{width:`${babelHelpers.classPrivateFieldLooseBase(this,We)[We].width}px`,height:`${babelHelpers.classPrivateFieldLooseBase(this,We)[We].height}px`,left:0,top:0}});o.Dom.adjust(babelHelpers.classPrivateFieldLooseBase(this,Ve)[Ve],{style:{transform:"none",width:`${babelHelpers.classPrivateFieldLooseBase(this,We)[We].width}px`,height:`${babelHelpers.classPrivateFieldLooseBase(this,We)[We].height}px`}});o.Dom.adjust(babelHelpers.classPrivateFieldLooseBase(this,Ge)[Ge],{style:{width:`${babelHelpers.classPrivateFieldLooseBase(this,We)[We].width}px`,height:`${babelHelpers.classPrivateFieldLooseBase(this,We)[We].height}px`,left:0,top:0}});this.disableToMove();this.emit("onReset",babelHelpers.classPrivateFieldLooseBase(this,Ve)[Ve])}set(e){const t={width:0,height:0,scale:1,name:e["name"]};if(e.clientWidth){t.width=e.clientWidth;t.height=e.clientHeight}else{t.width=e.width;t.height=e.height}if(t.width<=0||t.height<=0){return}const s=Math.ceil(Math.max(t.width>C.imageSize?C.imageSize/t.width:babelHelpers.classPrivateFieldLooseBase(this,Ye)[Ye]!==false&&t.width<babelHelpers.classPrivateFieldLooseBase(this,We)[We].width?babelHelpers.classPrivateFieldLooseBase(this,We)[We].width/t.width:1,t.height>C.imageSize?C.imageSize/t.height:babelHelpers.classPrivateFieldLooseBase(this,Ye)[Ye]!==false&&t.height<babelHelpers.classPrivateFieldLooseBase(this,We)[We].height?babelHelpers.classPrivateFieldLooseBase(this,We)[We].height/t.height:1)*1e3)/1e3;t.width=Math.ceil(t.width*s);t.height=Math.ceil(t.height*s);const a=Math.ceil(Math.max(t.width>0?babelHelpers.classPrivateFieldLooseBase(this,We)[We].width/t.width:1,t.height>0?babelHelpers.classPrivateFieldLooseBase(this,We)[We].height/t.height:1)*1e3)/1e3;t.scale=0<a&&a<1?a:1;o.Dom.adjust(babelHelpers.classPrivateFieldLooseBase(this,Ve)[Ve],{props:{width:t.width,height:t.height},style:{width:t.width+"px",height:t.height+"px",transform:"scale("+t.scale+", "+t.scale+")"},dataset:{width:t.width,height:t.height,scale:t.scale,initialScale:t.scale,hasChanged:false}});babelHelpers.classPrivateFieldLooseBase(this,qe)[qe]=true;babelHelpers.classPrivateFieldLooseBase(this,Xe)[Xe].drawImage(e,0,0,t.width,t.height);const i={width:babelHelpers.classPrivateFieldLooseBase(this,We)[We].width,height:babelHelpers.classPrivateFieldLooseBase(this,We)[We].height};const l={width:2*i.width+Math.ceil(t.scale*t.width),height:2*i.height+Math.ceil(t.scale*t.height),left:-1*Math.ceil((i.width+t.scale*t.width)/2),top:-1*Math.ceil((i.height+t.scale*t.height)/2)};o.Dom.adjust(babelHelpers.classPrivateFieldLooseBase(this,Je)[Je],{style:{width:`${l.width}px`,height:`${l.height}px`,top:`${l.top}px`,left:`${l.left}px`},dataset:{top:l.top,left:l.left,topToBeInTheCenter:l.top,leftToBeInTheCenter:l.left,height:l.height,width:l.width}});o.Dom.adjust(babelHelpers.classPrivateFieldLooseBase(this,Ge)[Ge],{style:{top:`${l.top*-1}px`,left:`${l.left*-1}px`}});this.enableToMove();this.emit("onSetImage",{canvas:babelHelpers.classPrivateFieldLooseBase(this,Ve)[Ve]})}scale(e){e=Math.max(.01,1+e);const t=Number(babelHelpers.classPrivateFieldLooseBase(this,Ve)[Ve].dataset.scale);const s=e*Number(babelHelpers.classPrivateFieldLooseBase(this,Ve)[Ve].dataset.initialScale);o.Dom.adjust(babelHelpers.classPrivateFieldLooseBase(this,Ve)[Ve],{style:{transform:"scale("+s+", "+s+")"},dataset:{scale:s,hasChanged:true}});const a={height:babelHelpers.classPrivateFieldLooseBase(this,We)[We].height,width:babelHelpers.classPrivateFieldLooseBase(this,We)[We].width};const i={height:2*a.height+Math.ceil(s*Number(babelHelpers.classPrivateFieldLooseBase(this,Ve)[Ve].dataset.height)),width:2*a.width+Math.ceil(s*Number(babelHelpers.classPrivateFieldLooseBase(this,Ve)[Ve].dataset.width)),topToBeInTheCenter:-1*Math.ceil((a.height+s*Number(babelHelpers.classPrivateFieldLooseBase(this,Ve)[Ve].dataset.height))/2),leftToBeInTheCenter:-1*Math.ceil((a.width+s*Number(babelHelpers.classPrivateFieldLooseBase(this,Ve)[Ve].dataset.width))/2),top:null,left:null};const l=babelHelpers.classPrivateFieldLooseBase(this,Je)[Je].dataset.top-babelHelpers.classPrivateFieldLooseBase(this,Je)[Je].dataset.topToBeInTheCenter;const r=l/t*s;i.top=Math.ceil(i.topToBeInTheCenter+r);i.top=Math.max(Math.min(i.top,0),-1*(Number(i.height)-a.height));const n=babelHelpers.classPrivateFieldLooseBase(this,Je)[Je].dataset.left-babelHelpers.classPrivateFieldLooseBase(this,Je)[Je].dataset.leftToBeInTheCenter;const c=n/t*s;i.left=Math.ceil(c+i.leftToBeInTheCenter);i.left=Math.max(Math.min(i.left,0),-1*(Number(i.width)-a.width));o.Dom.adjust(babelHelpers.classPrivateFieldLooseBase(this,Je)[Je],{style:{width:`${i.width}px`,height:`${i.height}px`,top:`${i.top}px`,left:`${i.left}px`},dataset:{top:i.top,left:i.left,topToBeInTheCenter:i.topToBeInTheCenter,leftToBeInTheCenter:i.leftToBeInTheCenter,height:i.height,width:i.width}});o.Dom.adjust(babelHelpers.classPrivateFieldLooseBase(this,Ge)[Ge],{style:{top:`${i.top*-1}px`,left:`${i.left*-1}px`}});this.emit("onScale",{zoomScale:e,scale:s,topOffsetFromTheCenter:Number(babelHelpers.classPrivateFieldLooseBase(this,Je)[Je].dataset.top)-Number(babelHelpers.classPrivateFieldLooseBase(this,Je)[Je].dataset.topToBeInTheCenter),leftOffsetFromTheCenter:Number(babelHelpers.classPrivateFieldLooseBase(this,Je)[Je].dataset.left)-Number(babelHelpers.classPrivateFieldLooseBase(this,Je)[Je].dataset.leftToBeInTheCenter),topInPercent:Math.ceil(babelHelpers.classPrivateFieldLooseBase(this,Je)[Je].dataset.top*1e3/Number(babelHelpers.classPrivateFieldLooseBase(this,Je)[Je].dataset.topToBeInTheCenter))/1e3,leftInPercent:Math.ceil(babelHelpers.classPrivateFieldLooseBase(this,Je)[Je].dataset.left*1e3/Number(babelHelpers.classPrivateFieldLooseBase(this,Je)[Je].dataset.leftToBeInTheCenter))/1e3,oldScale:t})}onScale({data:{oldScale:e,scale:t,topOffsetFromTheCenter:s,leftOffsetFromTheCenter:a,topInPercent:i,leftInPercent:l}}){const r=t/e;let n,c,d;if(Number(e)===Number(babelHelpers.classPrivateFieldLooseBase(this,Ve)[Ve].dataset.scale)){d=t}else{d=babelHelpers.classPrivateFieldLooseBase(this,Ve)[Ve].dataset.scale*r}o.Dom.adjust(babelHelpers.classPrivateFieldLooseBase(this,Ve)[Ve],{style:{transform:"scale("+d+", "+d+")"},dataset:{scale:d,hasChanged:true}});const b={height:babelHelpers.classPrivateFieldLooseBase(this,We)[We].height,width:babelHelpers.classPrivateFieldLooseBase(this,We)[We].width};const h={height:2*b.height+Math.ceil(d*Number(babelHelpers.classPrivateFieldLooseBase(this,Ve)[Ve].dataset.height)),width:2*b.width+Math.ceil(d*Number(babelHelpers.classPrivateFieldLooseBase(this,Ve)[Ve].dataset.width)),topToBeInTheCenter:-1*Math.ceil((b.height+d*Number(babelHelpers.classPrivateFieldLooseBase(this,Ve)[Ve].dataset.height))/2),leftToBeInTheCenter:-1*Math.ceil((b.width+d*Number(babelHelpers.classPrivateFieldLooseBase(this,Ve)[Ve].dataset.width))/2),top:null,left:null};if(Number(t)===Number(babelHelpers.classPrivateFieldLooseBase(this,Ve)[Ve].dataset.scale)){n=Number(babelHelpers.classPrivateFieldLooseBase(this,Je)[Je].dataset.topToBeInTheCenter)+s;c=Number(babelHelpers.classPrivateFieldLooseBase(this,Je)[Je].dataset.leftToBeInTheCenter)+a}else{n=Math.ceil(Number(babelHelpers.classPrivateFieldLooseBase(this,Je)[Je].dataset.topToBeInTheCenter)*i);c=Math.ceil(Number(babelHelpers.classPrivateFieldLooseBase(this,Je)[Je].dataset.leftToBeInTheCenter)*l)}h.top=Math.max(Math.min(n,0),-1*(Number(babelHelpers.classPrivateFieldLooseBase(this,Je)[Je].dataset.height)-babelHelpers.classPrivateFieldLooseBase(this,We)[We].height));h.left=Math.max(Math.min(c,0),-1*(Number(babelHelpers.classPrivateFieldLooseBase(this,Je)[Je].dataset.width)-babelHelpers.classPrivateFieldLooseBase(this,We)[We].width));o.Dom.adjust(babelHelpers.classPrivateFieldLooseBase(this,Je)[Je],{style:{width:`${h.width}px`,height:`${h.height}px`,top:`${h.top}px`,left:`${h.left}px`},dataset:{top:h.top,left:h.left,topToBeInTheCenter:h.topToBeInTheCenter,leftToBeInTheCenter:h.leftToBeInTheCenter,height:h.height,width:h.width}});o.Dom.adjust(babelHelpers.classPrivateFieldLooseBase(this,Ge)[Ge],{style:{top:`${h.top*-1}px`,left:`${h.left*-1}px`}})}enableToMove(){if(babelHelpers.classPrivateFieldLooseBase(this,We)[We].style.cursor==="move"){return}babelHelpers.classPrivateFieldLooseBase(this,We)[We].style.cursor="move";o.Event.bind(babelHelpers.classPrivateFieldLooseBase(this,We)[We],"mousedown",(e=>{this.cursor={startX:e.pageX,startY:e.pageY};o.Event.bind(document,"mousemove",this.mouseMove);o.Event.bind(document,"mouseup",this.stopMoving)}))}disableToMove(){babelHelpers.classPrivateFieldLooseBase(this,We)[We].style.cursor="default";o.Event.unbindAll(babelHelpers.classPrivateFieldLooseBase(this,We)[We]);o.Event.unbind(document,"mousemove",this.mouseMove);o.Event.unbind(document,"mouseup",this.stopMoving)}move(e,t){o.Dom.adjust(babelHelpers.classPrivateFieldLooseBase(this,Ve)[Ve],{dataset:{hasChanged:true}});const s={height:babelHelpers.classPrivateFieldLooseBase(this,We)[We].height,width:babelHelpers.classPrivateFieldLooseBase(this,We)[We].width};const a=Math.max(Math.min(Number(babelHelpers.classPrivateFieldLooseBase(this,Je)[Je].dataset.left)-e,0),-1*(Number(babelHelpers.classPrivateFieldLooseBase(this,Je)[Je].dataset.width)-s.width));const i=Math.max(Math.min(Number(babelHelpers.classPrivateFieldLooseBase(this,Je)[Je].dataset.top)-t,0),-1*(Number(babelHelpers.classPrivateFieldLooseBase(this,Je)[Je].dataset.height)-s.height));o.Dom.adjust(babelHelpers.classPrivateFieldLooseBase(this,Je)[Je],{style:{top:`${i}px`,left:`${a}px`},dataset:{top:i,left:a}});this.emit("onMove",{topOffsetFromTheCenter:i-Number(babelHelpers.classPrivateFieldLooseBase(this,Je)[Je].dataset.topToBeInTheCenter),leftOffsetFromTheCenter:a-Number(babelHelpers.classPrivateFieldLooseBase(this,Je)[Je].dataset.leftToBeInTheCenter),scale:babelHelpers.classPrivateFieldLooseBase(this,Ve)[Ve].dataset.scale,topInPercent:Math.ceil(i*1e3/Number(babelHelpers.classPrivateFieldLooseBase(this,Je)[Je].dataset.topToBeInTheCenter))/1e3,leftInPercent:Math.ceil(a*1e3/Number(babelHelpers.classPrivateFieldLooseBase(this,Je)[Je].dataset.leftToBeInTheCenter))/1e3});o.Dom.adjust(babelHelpers.classPrivateFieldLooseBase(this,Ge)[Ge],{style:{top:`${i*-1}px`,left:`${a*-1}px`}})}onMove({data:{scale:e,topOffsetFromTheCenter:t,leftOffsetFromTheCenter:s,topInPercent:a,leftInPercent:i}}){let l,r;if(Number(e)===Number(babelHelpers.classPrivateFieldLooseBase(this,Ve)[Ve].dataset.scale)){l=Number(babelHelpers.classPrivateFieldLooseBase(this,Je)[Je].dataset.topToBeInTheCenter)+t;r=Number(babelHelpers.classPrivateFieldLooseBase(this,Je)[Je].dataset.leftToBeInTheCenter)+s}else{l=Math.ceil(Number(babelHelpers.classPrivateFieldLooseBase(this,Je)[Je].dataset.topToBeInTheCenter)*a);r=Math.ceil(Number(babelHelpers.classPrivateFieldLooseBase(this,Je)[Je].dataset.leftToBeInTheCenter)*i)}r=Math.max(Math.min(r,0),-1*(Number(babelHelpers.classPrivateFieldLooseBase(this,Je)[Je].dataset.width)-babelHelpers.classPrivateFieldLooseBase(this,We)[We].width));l=Math.max(Math.min(l,0),-1*(Number(babelHelpers.classPrivateFieldLooseBase(this,Je)[Je].dataset.height)-babelHelpers.classPrivateFieldLooseBase(this,We)[We].height));o.Dom.adjust(babelHelpers.classPrivateFieldLooseBase(this,Je)[Je],{style:{top:`${l}px`,left:`${r}px`},dataset:{top:l,left:r}})}mouseMove(e){if(this.cursor===null){return}this.move(this.cursor.startX-e.pageX,this.cursor.startY-e.pageY);this.cursor.startX=e.pageX;this.cursor.startY=e.pageY}stopMoving(){BX.unbind(document,"mousemove",this.mouseMove);BX.unbind(document,"mouseup",this.stopMoving)}getCanvas(){return babelHelpers.classPrivateFieldLooseBase(this,Ve)[Ve]}getContext(){return babelHelpers.classPrivateFieldLooseBase(this,Xe)[Xe]}getTable(){return babelHelpers.classPrivateFieldLooseBase(this,We)[We]}getTableCloth(){return babelHelpers.classPrivateFieldLooseBase(this,Je)[Je]}packBlob(){if(babelHelpers.classPrivateFieldLooseBase(this,qe)[qe]!==true){return Promise.reject({message:"Source canvas does not exist.",code:"empty data"})}return new Promise(((e,t)=>{const s={height:babelHelpers.classPrivateFieldLooseBase(this,We)[We].height,width:babelHelpers.classPrivateFieldLooseBase(this,We)[We].width};const a=babelHelpers.classPrivateFieldLooseBase(this,Ve)[Ve].dataset.scale;const i=Math.min(C.imageSize,Math.max(babelHelpers.classPrivateFieldLooseBase(this,We)[We].width/a,babelHelpers.classPrivateFieldLooseBase(this,We)[We].width));const l=i/babelHelpers.classPrivateFieldLooseBase(this,We)[We].width;const r=Ke.getInstance();r.getCanvas().height=i;r.getCanvas().width=i;r.getContext().clearRect(0,0,i,i);let o,n,c;let d,b;o=-1*(babelHelpers.classPrivateFieldLooseBase(this,Je)[Je].dataset.topToBeInTheCenter-babelHelpers.classPrivateFieldLooseBase(this,Je)[Je].dataset.top)+s.height/2-babelHelpers.classPrivateFieldLooseBase(this,Ve)[Ve].height*a/2;if(o>0){d=o;n=0}else{d=0;n=-1*o}c=o+babelHelpers.classPrivateFieldLooseBase(this,Ve)[Ve].height*a;if(c>s.height){b=s.height;c=s.height-o}else{b=c;c=babelHelpers.classPrivateFieldLooseBase(this,Ve)[Ve].height*a}let h,v,p;let u,m;h=-1*(babelHelpers.classPrivateFieldLooseBase(this,Je)[Je].dataset.leftToBeInTheCenter-babelHelpers.classPrivateFieldLooseBase(this,Je)[Je].dataset.left)+s.width/2-babelHelpers.classPrivateFieldLooseBase(this,Ve)[Ve].width*a/2;if(h>0){u=h;v=0}else{u=0;v=-1*h}p=h+babelHelpers.classPrivateFieldLooseBase(this,Ve)[Ve].width*a;if(p>s.width){m=s.width;p=s.width-h}else{m=p;p=babelHelpers.classPrivateFieldLooseBase(this,Ve)[Ve].width*a}v/=a;p/=a;n/=a;c/=a;u*=l;d*=l;m*=l;b*=l;r.getContext().drawImage(babelHelpers.classPrivateFieldLooseBase(this,Ve)[Ve],v,n,p-v,c-n,u,d,m-u,b-d);const g=babelHelpers.classPrivateFieldLooseBase(this,Ve)[Ve].dataset.changed;r.pack().then((t=>{t.changed=g;t.width=i;t.height=i;e(t)})).catch((e=>{t(e)}))}))}}Ze.imageSize={width:1024,height:1024};var Qe=babelHelpers.classPrivateFieldLooseKey("fileName");var et=babelHelpers.classPrivateFieldLooseKey("applyNameAndExtensionToBlob");class tt extends Ze{constructor(...e){super(...e);Object.defineProperty(this,et,{value:st});Object.defineProperty(this,Qe,{writable:true,value:void 0})}load(e){this.emit("onLoad");babelHelpers.classPrivateFieldLooseBase(this,Qe)[Qe]=null;return new Promise(((t,s)=>{this.reset();Ke.loadFile(e,(e=>{babelHelpers.classPrivateFieldLooseBase(this,Qe)[Qe]=e.name;this.set(e);t()}),(()=>{this.emit("onError",o.Loc.getMessage("JS_AVATAR_EDITOR_ERROR_IMAGE_DEPLOYING"));s()}))}))}getBlob(){return new Promise(((e,t)=>{this.packBlob().then((t=>{babelHelpers.classPrivateFieldLooseBase(this,et)[et](t);e({blob:t})})).catch(t)}))}}function st(e){e.name=babelHelpers.classPrivateFieldLooseBase(this,Qe)[Qe]||"image";let t=e.name.split(".").pop().toLowerCase();t=t===e.name?"":t;if(e.type==="image/png"&&t!=="png"){if("jpg,bmp,jpeg,jpe,gif,png,webp".lastIndexOf(t)>0){e.name=e.name.substr(0,e.name.lastIndexOf("."))}e.name=[e.name||"image","png"].join(".")}return e}class at extends Ze{}var it=babelHelpers.classPrivateFieldLooseKey("stepSize");var lt=babelHelpers.classPrivateFieldLooseKey("value");var rt=babelHelpers.classPrivateFieldLooseKey("defaultValue");var ot=babelHelpers.classPrivateFieldLooseKey("containerWidth");var nt=babelHelpers.classPrivateFieldLooseKey("scale");var ct=babelHelpers.classPrivateFieldLooseKey("knob");var dt=babelHelpers.classPrivateFieldLooseKey("getContainerWidth");var bt=babelHelpers.classPrivateFieldLooseKey("makeAStep");var ht=babelHelpers.classPrivateFieldLooseKey("adjust");class vt extends n.EventEmitter{constructor({knob:e,scale:t,minus:s,plus:a},i){super();Object.defineProperty(this,ht,{value:mt});Object.defineProperty(this,bt,{value:ut});Object.defineProperty(this,dt,{value:pt});Object.defineProperty(this,it,{writable:true,value:.01});Object.defineProperty(this,lt,{writable:true,value:0});Object.defineProperty(this,rt,{writable:true,value:0});Object.defineProperty(this,ot,{writable:true,value:0});Object.defineProperty(this,nt,{writable:true,value:void 0});Object.defineProperty(this,ct,{writable:true,value:void 0});this.setEventNamespace("Main.Avatar.Editor");o.Event.bind(s,"click",(()=>{babelHelpers.classPrivateFieldLooseBase(this,bt)[bt](false)}));o.Event.bind(a,"click",(()=>{babelHelpers.classPrivateFieldLooseBase(this,bt)[bt](true)}));this.stopMoving=this.stopMoving.bind(this);this.move=this.move.bind(this);o.Event.bind(e,"mousedown",(e=>{this.startMoving(e)}));if(i){this.setDefaultValue(i)}babelHelpers.classPrivateFieldLooseBase(this,nt)[nt]=t;babelHelpers.classPrivateFieldLooseBase(this,ct)[ct]=e;this.reset()}setDefaultValue(e){babelHelpers.classPrivateFieldLooseBase(this,rt)[rt]=e>0&&e<=1?e:0;return this}getValue(){return babelHelpers.classPrivateFieldLooseBase(this,lt)[lt]}reset(){babelHelpers.classPrivateFieldLooseBase(this,lt)[lt]=babelHelpers.classPrivateFieldLooseBase(this,rt)[rt];babelHelpers.classPrivateFieldLooseBase(this,ht)[ht]()}setValue(e){e=Math.ceil(e*1e3)/1e3;if(e!==babelHelpers.classPrivateFieldLooseBase(this,lt)[lt]&&e>=0&&e<=1){babelHelpers.classPrivateFieldLooseBase(this,lt)[lt]=e;babelHelpers.classPrivateFieldLooseBase(this,ht)[ht]();this.emit("onChange",babelHelpers.classPrivateFieldLooseBase(this,lt)[lt]-babelHelpers.classPrivateFieldLooseBase(this,rt)[rt])}}move({pageX:e}){if(e>0&&babelHelpers.classPrivateFieldLooseBase(this,dt)[dt]()>0){const t=(e-babelHelpers.classPrivateFieldLooseBase(this,ct)[ct].startPageX)/babelHelpers.classPrivateFieldLooseBase(this,dt)[dt]();babelHelpers.classPrivateFieldLooseBase(this,ct)[ct].startPageX=e;this.setValue(this.getValue()+t)}}startMoving({pageX:e}){babelHelpers.classPrivateFieldLooseBase(this,ct)[ct].startPageX=e;o.Event.bind(document,"mousemove",this.move);o.Event.bind(document,"mouseup",this.stopMoving)}stopMoving(){o.Event.unbind(document,"mousemove",this.move);o.Event.unbind(document,"mouseup",this.stopMoving)}}function pt(){if(babelHelpers.classPrivateFieldLooseBase(this,ot)[ot]>0){return babelHelpers.classPrivateFieldLooseBase(this,ot)[ot]}const e=o.Dom.getPosition(babelHelpers.classPrivateFieldLooseBase(this,nt)[nt]);let t=e.width-o.Dom.getPosition(babelHelpers.classPrivateFieldLooseBase(this,ct)[ct]).width;if(t>0){babelHelpers.classPrivateFieldLooseBase(this,ot)[ot]=t;return babelHelpers.classPrivateFieldLooseBase(this,ot)[ot]}return 0}function ut(e){const t=Math.min(Math.max(this.getValue()+(e===false?-1:1)*babelHelpers.classPrivateFieldLooseBase(this,it)[it],0),1);this.setValue(t)}function mt(){o.Dom.adjust(babelHelpers.classPrivateFieldLooseBase(this,ct)[ct],{style:{left:[Math.ceil(babelHelpers.classPrivateFieldLooseBase(this,dt)[dt]()*this.getValue()),"px"].join("")}})}var gt=babelHelpers.classPrivateFieldLooseKey("canvas");var Pt=babelHelpers.classPrivateFieldLooseKey("ctx");var Lt=babelHelpers.classPrivateFieldLooseKey("container");var Bt=babelHelpers.classPrivateFieldLooseKey("activeMask");class Ft extends n.EventEmitter{constructor(e){super();Object.defineProperty(this,gt,{writable:true,value:void 0});Object.defineProperty(this,Pt,{writable:true,value:void 0});Object.defineProperty(this,Lt,{writable:true,value:void 0});Object.defineProperty(this,Bt,{writable:true,value:null});this.setEventNamespace("Main.Avatar.Editor");babelHelpers.classPrivateFieldLooseBase(this,Lt)[Lt]=e;this.set=this.set.bind(this);this.mask=this.mask.bind(this);this.unmask=this.unmask.bind(this)}mask({id:e,src:t,thumb:s}){o.Dom.style(babelHelpers.classPrivateFieldLooseBase(this,Lt)[Lt],"background-image",'url("'+o.Text.encode(s)+'")');babelHelpers.classPrivateFieldLooseBase(this,Bt)[Bt]={id:e,src:t};Ke.loadFile(t,this.set,this.unmask)}set(e){const t=Math.max(e.width>0?C.maskSize/e.width:1,e.height>0?C.maskSize/e.height:1);const s=parseInt(C.maskSize/t);const a=parseInt((e.width-s)/2);const i=parseInt((e.height-s)/2);this.getCanvas().width=C.maskSize;this.getCanvas().height=C.maskSize;this.getContext().clearRect(0,0,C.maskSize,C.maskSize);this.getContext().drawImage(e,a,i,s,s,0,0,C.maskSize,C.maskSize)}applyAndPack(e){if(babelHelpers.classPrivateFieldLooseBase(this,Bt)[Bt]===null||e.width<100||e.height<100){return Promise.reject({message:"Image for masking has not appropriate format",code:"bad image"})}return new Promise((t=>{const s=Math.max(e.width>0?C.maskSize/e.width:1,e.height>0?C.maskSize/e.height:1);const a=parseInt(C.maskSize/s);const i=parseInt((e.width-a)/2);const l=parseInt((e.height-a)/2);const r=Ke.getInstance();r.getCanvas().width=C.maskSize;r.getCanvas().height=C.maskSize;r.getContext().clearRect(0,0,C.maskSize,C.maskSize);r.getContext().drawImage(e,i,l,a,a,0,0,C.maskSize,C.maskSize);r.getContext().drawImage(this.getCanvas(),0,0,C.maskSize,C.maskSize);r.pack("image/png").then((e=>{e.name="mask.png";e.maskId=babelHelpers.classPrivateFieldLooseBase(this,Bt)[Bt].id;t(e,babelHelpers.classPrivateFieldLooseBase(this,Bt)[Bt].id)}))}))}getCanvas(){if(!babelHelpers.classPrivateFieldLooseBase(this,gt)[gt]){babelHelpers.classPrivateFieldLooseBase(this,gt)[gt]=document.createElement("CANVAS")}return babelHelpers.classPrivateFieldLooseBase(this,gt)[gt]}getContext(){if(!babelHelpers.classPrivateFieldLooseBase(this,Pt)[Pt]){babelHelpers.classPrivateFieldLooseBase(this,Pt)[Pt]=this.getCanvas().getContext("2d")}return babelHelpers.classPrivateFieldLooseBase(this,Pt)[Pt]}unmask(){babelHelpers.classPrivateFieldLooseBase(this,Lt)[Lt].style.backgroundImage="";babelHelpers.classPrivateFieldLooseBase(this,Bt)[Bt]=null}}let Ht=e=>e,ft;const yt=Symbol("hiddenCanvas");var _t=babelHelpers.classPrivateFieldLooseKey("id");var Tt=babelHelpers.classPrivateFieldLooseKey("activeTabId");var wt=babelHelpers.classPrivateFieldLooseKey("previousActiveTabId");var xt=babelHelpers.classPrivateFieldLooseKey("tabs");var kt=babelHelpers.classPrivateFieldLooseKey("canvasMaster");var At=babelHelpers.classPrivateFieldLooseKey("canvasPreview");var Ct=babelHelpers.classPrivateFieldLooseKey("canvasZooming");var It=babelHelpers.classPrivateFieldLooseKey("canvasMask");var St=babelHelpers.classPrivateFieldLooseKey("setActiveTabByDefault");var Mt=babelHelpers.classPrivateFieldLooseKey("setPreviousActiveTab");var Et=babelHelpers.classPrivateFieldLooseKey("selectFile");var Ot=babelHelpers.classPrivateFieldLooseKey("snapAPicture");class Rt extends n.EventEmitter{constructor(e){super();Object.defineProperty(this,Ot,{value:Kt});Object.defineProperty(this,Et,{value:Nt});Object.defineProperty(this,Mt,{value:jt});Object.defineProperty(this,St,{value:Dt});Object.defineProperty(this,_t,{writable:true,value:0});Object.defineProperty(this,Tt,{writable:true,value:void 0});Object.defineProperty(this,wt,{writable:true,value:void 0});Object.defineProperty(this,xt,{writable:true,value:new Map});this.cache=new o.Cache.MemoryCache;Object.defineProperty(this,kt,{writable:true,value:void 0});Object.defineProperty(this,At,{writable:true,value:void 0});Object.defineProperty(this,Ct,{writable:true,value:void 0});Object.defineProperty(this,It,{writable:true,value:void 0});this.setEventNamespace("Main.Avatar.Editor");babelHelpers.classPrivateFieldLooseBase(this,_t)[_t]=Rt.justANumber++;e=o.Type.isPlainObject(e)?e:{};const t=[[we,true],[fe,e.enableMask,null]];t.forEach((([e,t,s])=>{if(t===true&&e.isAvailable()!==false){const t=new e(s);babelHelpers.classPrivateFieldLooseBase(this,xt)[xt].set(e.code,t);t.subscribe("onSetMask",(({data:e})=>{this.getContainer().setAttribute("data-badge-is-set","Y");babelHelpers.classPrivateFieldLooseBase(this,It)[It].mask(e)}));t.subscribe("onUnsetMask",(()=>{this.getContainer().removeAttribute("data-badge-is-set");babelHelpers.classPrivateFieldLooseBase(this,It)[It].unmask()}))}}));const s=[[A,e.enableUpload,e.uploadTabOptions],[H,e.enableCamera,null]];s.forEach((([e,t,s])=>{if(t!==false&&e.isAvailable()!==false){const t=new e(s);babelHelpers.classPrivateFieldLooseBase(this,xt)[xt].set(e.code,t);t.setParentTab(babelHelpers.classPrivateFieldLooseBase(this,xt)[xt].get(we.code));t.subscribe("onClickBack",(()=>{this.setActiveTab(we.code)}));t.subscribe("onSetFile",(({data:e})=>{if(e instanceof Blob){babelHelpers.classPrivateFieldLooseBase(this,kt)[kt].load(e)}else{babelHelpers.classPrivateFieldLooseBase(this,kt)[kt].set(e)}this.setActiveTab(we.code)}));if(t instanceof H){this.subscribe("onOpen",(()=>{if(babelHelpers.classPrivateFieldLooseBase(this,Tt)[Tt]===H.code){t.activate.call(t)}}));this.subscribe("onClose",(()=>{if(babelHelpers.classPrivateFieldLooseBase(this,Tt)[Tt]===H.code){t.inactivate.call(t)}}))}}}));let a=babelHelpers.classPrivateFieldLooseBase(this,Tt)[Tt];babelHelpers.classPrivateFieldLooseBase(this,xt)[xt].forEach(((e,t)=>{if(!a||babelHelpers.classPrivateFieldLooseBase(this,xt)[xt].get(a).getPriority()<e.getPriority()){a=t}}));babelHelpers.classPrivateFieldLooseBase(this,St)[St](a);n.EventEmitter.subscribe(this.getEventNamespace()+":"+"onEditMask",(e=>{}));n.EventEmitter.subscribe(this.getEventNamespace()+":"+"onDeleteMask",(e=>{}));this.init()}init(){if(!this.getContainer().querySelector('canvas[data-bx-canvas="canvas"]')){return setTimeout(this.init.bind(this),1)}const e=[A,H];e.forEach((e=>{this.getContainer().setAttribute("data-bx-"+e.code+"-tab-available",babelHelpers.classPrivateFieldLooseBase(this,xt)[xt].has(e.code)?"Y":"N")}));babelHelpers.classPrivateFieldLooseBase(this,kt)[kt]=new tt(this.getContainer().querySelector('canvas[data-bx-canvas="canvas"]'));babelHelpers.classPrivateFieldLooseBase(this,At)[At]=new at(this.getContainer().querySelector('canvas[data-bx-canvas="preview"]'));babelHelpers.classPrivateFieldLooseBase(this,Ct)[Ct]=new vt({knob:this.getContainer().querySelector('[data-bx-role="zoom-knob"]'),scale:this.getContainer().querySelector('[data-bx-role="zoom-scale"]'),plus:this.getContainer().querySelector('[data-bx-role="zoom-plus-button"]'),minus:this.getContainer().querySelector('[data-bx-role="zoom-minus-button"]')});babelHelpers.classPrivateFieldLooseBase(this,It)[It]=babelHelpers.classPrivateFieldLooseBase(this,xt)[xt].has(fe.code)?new Ft(this.getContainer().querySelector('[data-bx-role="canvas-mask"]')):false;this.getContainer().querySelector('[data-bx-role="unset-canvas-mask"]').addEventListener("click",(()=>{this.getContainer().removeAttribute("data-badge-is-set");babelHelpers.classPrivateFieldLooseBase(this,It)[It].unmask();babelHelpers.classPrivateFieldLooseBase(this,xt)[xt].get(fe.code).unmask()}));babelHelpers.classPrivateFieldLooseBase(this,kt)[kt].subscribe("onLoad",(e=>{this.getContainer().setAttribute("data-bx-canvas-load-status","loading");this.emit("onChange")}));babelHelpers.classPrivateFieldLooseBase(this,kt)[kt].subscribe("onReset",(e=>{this.getContainer().setAttribute("data-bx-canvas-load-status","isnotset");babelHelpers.classPrivateFieldLooseBase(this,Ct)[Ct].reset();babelHelpers.classPrivateFieldLooseBase(this,At)[At].reset();this.emit("onChange")}));this.getContainer().setAttribute("data-bx-canvas-load-status","isnotset");babelHelpers.classPrivateFieldLooseBase(this,kt)[kt].subscribe("onSetImage",(({data:{canvas:e}})=>{this.getContainer().setAttribute("data-bx-canvas-load-status","set");babelHelpers.classPrivateFieldLooseBase(this,Ct)[Ct].reset();babelHelpers.classPrivateFieldLooseBase(this,At)[At].set(e);this.emit("onSet");this.emit("onChange")}));babelHelpers.classPrivateFieldLooseBase(this,kt)[kt].subscribe("onMove",(e=>{babelHelpers.classPrivateFieldLooseBase(this,At)[At].onMove(e);this.emit("onChange")}));babelHelpers.classPrivateFieldLooseBase(this,kt)[kt].subscribe("onScale",(e=>{babelHelpers.classPrivateFieldLooseBase(this,At)[At].onScale(e);this.emit("onChange")}));babelHelpers.classPrivateFieldLooseBase(this,Ct)[Ct].subscribe("onChange",(({data:e})=>{babelHelpers.classPrivateFieldLooseBase(this,kt)[kt].scale(e)}));babelHelpers.classPrivateFieldLooseBase(this,kt)[kt].subscribe("onError",(({data:e})=>{this.getContainer().setAttribute("data-bx-canvas-load-status","errored");babelHelpers.classPrivateFieldLooseBase(this,Ct)[Ct].reset();babelHelpers.classPrivateFieldLooseBase(this,At)[At].reset();this.getContainer().querySelector('[data-bx-role="tab-canvas-error"]').innerHTML=e}));this.emit("onReady")}ready(e){if(babelHelpers.classPrivateFieldLooseBase(this,kt)[kt]){e.call()}else{this.subscribe("onReady",e)}return this}getId(){return babelHelpers.classPrivateFieldLooseBase(this,_t)[_t]}getContainer(){return this.cache.remember("container",(()=>{const e=o.Tag.render(ft||(ft=Ht`
				<div class="ui-avatar-editor__tab-wrapper ui-avatar-editor--scope">
					<input type="hidden" data-bx-active-tab="doesNotMatterForNowItIsAFile">
					<div class="ui-avatar-editor__tab-button-container" data-bx-role="headers" style="display:none;"></div>
					<div class="ui-avatar-editor__tab-container">
						<div data-bx-role="bodies"></div>
						<div class="ui-avatar-editor__tab-avatar-block">
							<div class="ui-avatar-editor__tab-avatar-inner">
								<div class="ui-avatar-editor__arrow-icon-container">
									<span class="ui-avatar-editor__arrow-icon"></span>
								</div>
								<div class="ui-avatar-editor__tab-avatar-image-container">
									<div data-bx-role="unset-canvas-mask" class="ui-avatar-editor__tab-avatar-image-not-allowed"></div>
									<span class="ui-avatar-editor__tab-avatar-image-item" data-bx-role="canvas-button">
										<div data-editor-role="preview-holder">
											<canvas data-bx-canvas="preview" height="165" width="165"></canvas>
										</div>
										<div class="ui-avatar-editor__tab-avatar-mask" data-bx-role="canvas-mask"></div>
									</span>
								</div>
								<div class="ui-avatar-editor__tab-avatar-desc-container">
									<span class="ui-avatar-editor__tab-avatar-desc-item"></span>
								</div>
							</div>
						</div>
					</div>
				</div>`));const t=e.querySelector('[data-bx-role="headers"]');const s=e.querySelector('[data-bx-role="bodies"]');Array.from(babelHelpers.classPrivateFieldLooseBase(this,xt)[xt].entries()).forEach((([e,a])=>{o.Event.bind(a.getHeaderContainer(),"click",(()=>{this.setActiveTab(e)}));o.Dom.append(a.getHeaderContainer(),t);o.Dom.append(a.getBodyContainer(),s)}));if(t.querySelectorAll('[data-bx-state="visible"]').length>1){t.style.display="block"}[[A.code,e.querySelector('[data-bx-role="button-add-picture"][data-bx-id="upload-file"]'),()=>{babelHelpers.classPrivateFieldLooseBase(this,Et)[Et]()}],[H.code,e.querySelector('[data-bx-role="button-add-picture"][data-bx-id="snap-picture"]'),()=>{babelHelpers.classPrivateFieldLooseBase(this,Ot)[Ot]()}]].forEach((([e,t,s])=>{if(babelHelpers.classPrivateFieldLooseBase(this,xt)[xt].has(e)){o.Event.bind(t,"click",s)}else{o.Dom.remove(t)}}));return e}))}setActiveTab(e,t=false){if(!babelHelpers.classPrivateFieldLooseBase(this,xt)[xt].has(e)){return null}const s=this.cache.get("activeTabChangesCounter")||0;if(babelHelpers.classPrivateFieldLooseBase(this,Tt)[Tt]!==e){if(babelHelpers.classPrivateFieldLooseBase(this,Tt)[Tt]===null){babelHelpers.classPrivateFieldLooseBase(this,Tt)[Tt]=e}else if(babelHelpers.classPrivateFieldLooseBase(this,xt)[xt].has(babelHelpers.classPrivateFieldLooseBase(this,Tt)[Tt])){babelHelpers.classPrivateFieldLooseBase(this,xt)[xt].get(babelHelpers.classPrivateFieldLooseBase(this,Tt)[Tt]).inactivate()}if(babelHelpers.classPrivateFieldLooseBase(this,Tt)[Tt]===A.code||babelHelpers.classPrivateFieldLooseBase(this,Tt)[Tt]===H.code){babelHelpers.classPrivateFieldLooseBase(this,wt)[wt]=babelHelpers.classPrivateFieldLooseBase(this,Tt)[Tt]}babelHelpers.classPrivateFieldLooseBase(this,Tt)[Tt]=e;babelHelpers.classPrivateFieldLooseBase(this,xt)[xt].get(babelHelpers.classPrivateFieldLooseBase(this,Tt)[Tt]).activate()}this.cache.set("activeTabChangesCounter",s+1);return babelHelpers.classPrivateFieldLooseBase(this,xt)[xt].get(babelHelpers.classPrivateFieldLooseBase(this,Tt)[Tt])}getTab(e){return babelHelpers.classPrivateFieldLooseBase(this,xt)[xt].get(e)}loadJSON(e){return this.loadData(JSON.parse(e))}loadData(e){return new Promise(((t,s)=>{if(o.Type.isPlainObject(e)&&e["src"]){babelHelpers.classPrivateFieldLooseBase(this,kt)[kt].load(e["src"]).then((()=>{if(e["maskId"]&&babelHelpers.classPrivateFieldLooseBase(this,xt)[xt].has(fe.code)){babelHelpers.classPrivateFieldLooseBase(this,xt)[xt].get(fe.code).maskById(e["maskId"]);babelHelpers.classPrivateFieldLooseBase(this,St)[St](fe.code)}else{babelHelpers.classPrivateFieldLooseBase(this,St)[St](we.code)}t(e["src"],this)})).catch(s)}else{babelHelpers.classPrivateFieldLooseBase(this,St)[St](A.code);t(null,this)}}))}loadSrc(e){return new Promise(((t,s)=>{babelHelpers.classPrivateFieldLooseBase(this,kt)[kt].load(e).then((()=>{this.setActiveTab(babelHelpers.classPrivateFieldLooseBase(this,xt)[xt].has(fe.code)?fe.code:we.code);t(e,this)})).catch((()=>{babelHelpers.classPrivateFieldLooseBase(this,Mt)[Mt]();s(e,this)}))}))}reset(){babelHelpers.classPrivateFieldLooseBase(this,kt)[kt].reset();babelHelpers.classPrivateFieldLooseBase(this,Mt)[Mt]();return this}packBlobAndMask(){return new Promise(((e,t)=>{babelHelpers.classPrivateFieldLooseBase(this,kt)[kt].getBlob().then((({blob:t})=>{var s;const a=Ke.getInstance();a[yt]=(s=a[yt])!=null?s:document.createElement("canvas");const i=a[yt];i.width=t.width;i.height=t.height;i.getContext("2d").drawImage(a.getCanvas(),0,0);if(!babelHelpers.classPrivateFieldLooseBase(this,It)[It]){return e({blob:t,canvas:i})}babelHelpers.classPrivateFieldLooseBase(this,It)[It].applyAndPack(i).then(((s,a)=>{e({blob:t,maskedBlob:s,maskId:a,canvas:i})})).catch((()=>{e({blob:t,canvas:i})}))})).catch((e=>t(e)))}))}packBlob(){return new Promise(((e,t)=>{babelHelpers.classPrivateFieldLooseBase(this,kt)[kt].getBlob().then(e).catch(t)}))}isEmpty(){return babelHelpers.classPrivateFieldLooseBase(this,kt)[kt].isEmpty()}isModified(){return babelHelpers.classPrivateFieldLooseBase(this,kt)[kt].imageFrame.changed}getCanvasEditor(){return babelHelpers.classPrivateFieldLooseBase(this,kt)[kt]}getCanvasZooming(){return babelHelpers.classPrivateFieldLooseBase(this,Ct)[Ct]}destroy(){}static createInstance(e,t){if(this.repo.has(e)){this.repo.get(e).destroy()}const s=new this(t);if(document.querySelector("#"+e)){s.ready((()=>{s.loadJSON(document.querySelector("#"+e).getAttribute("data-bx-ui-avatar-editor-info"))}))}if(o.Type.isStringFilled(e)){this.repo.set(e,s)}return s}static getInstanceById(e){if(this.repo.has(e)){return this.repo.get(e)}return null}static getOrCreateInstanceById(e,t){return this.getInstanceById(e)||this.createInstance(...arguments)}}function Dt(e){if(this.cache.get("activeTabChangesCounter")>0){return}this.setActiveTab(e);this.cache.delete("activeTabChangesCounter")}function jt(){this.setActiveTab(babelHelpers.classPrivateFieldLooseBase(this,wt)[wt])}function Nt(){this.setActiveTab(A.code);return this}function Kt(){this.setActiveTab(H.code);return this}Rt.justANumber=0;Rt.repo=new Map;var Ut=babelHelpers.classPrivateFieldLooseKey("getPopup");class $t extends Rt{constructor(...e){super(...e);Object.defineProperty(this,Ut,{value:zt})}hide(){babelHelpers.classPrivateFieldLooseBase(this,Ut)[Ut]().close()}show(e){this.ready((()=>{babelHelpers.classPrivateFieldLooseBase(this,Ut)[Ut]().show();if(o.Type.isStringFilled(e)){this.setActiveTab(e)}}))}showFile(e){this.ready((()=>{babelHelpers.classPrivateFieldLooseBase(this,Ut)[Ut]().show();if(e){return this.loadSrc(e)}}))}apply(){this.packBlobAndMask().then((({blob:e,maskedBlob:t,maskId:s,canvas:a})=>{if(e instanceof Blob){if(s>0){y.useRecently(s)}const i=new n.BaseEvent({compatData:[e,a],data:{blob:e,maskedBlob:t}});n.EventEmitter.emit(this,"onApply",i,{useGlobalNaming:true});this.emit("onApply",i)}})).catch((e=>{console.log("error: ",e)}))}onApply(e){this.subscribe("onApply",e);return this}subscribeOnFormIsReady(e,t){this.subscribe("onApply",(s=>{const a=new FormData;const{blob:i,maskedBlob:l}=s.getData();a.append(e,i,i["name"]);const r=["maskedFile",Rt.justANumber++].join(":");a.append(o.Loc.getMessage("UI_AVATAR_MASK_REQUEST_FIELD_NAME")+e,r);if(l){a.append(o.Loc.getMessage("UI_AVATAR_MASK_REQUEST_FIELD_NAME")+"["+r+"]",l,i["name"]);a.append(o.Loc.getMessage("UI_AVATAR_MASK_REQUEST_FIELD_NAME")+"["+r+"][maskId]",l["maskId"]);t(new n.BaseEvent({data:{form:a,blob:i,maskedBlob:l,maskId:l["maskId"]}}))}else{t(new n.BaseEvent({data:{form:a,blob:i}}))}}))}click(){this.show()}get popup(){return babelHelpers.classPrivateFieldLooseBase(this,Ut)[Ut]()}static isCameraAvailable(){return H.isAvailable()}}function zt(){this.cache.remember("okButton",(()=>{const e=new d.SaveButton({onclick:()=>{if(e.getState()===d.ButtonState.ACTIVE){this.apply()}this.hide()}});if(this.isEmpty()){e.setState(d.ButtonState.DISABLED);this.subscribeOnce("onSet",(()=>{e.setState(d.ButtonState.ACTIVE)}))}return e}));return this.cache.remember("popup",(()=>c.PopupManager.create("popup_"+this.getId(),null,{className:"ui-avatar-editor__popup",autoHide:false,lightShadow:true,closeIcon:true,closeByEsc:true,titleBar:o.Loc.getMessage("JS_AVATAR_EDITOR_TITLE_BAR"),content:this.getContainer(),zIndex:BX.PopupWindowManager.getMaxZIndex()+1,overlay:{},contentColor:"white",contentNoPaddings:true,bindOnResize:false,draggable:true,isScrollBlock:true,buttons:[this.cache.remember("okButton"),new d.CancelButton({onclick:()=>{this.hide()}})],events:{onShow:()=>{this.emit("onOpen")},onClose:()=>{this.emit("onClose")}}})))}var qt=babelHelpers.classPrivateFieldLooseKey("id");var Vt=babelHelpers.classPrivateFieldLooseKey("showSlider");let Xt=$t;function Wt(){return Xt.createInstance(...arguments)}function Jt(){return Xt.isCameraAvailable()}function Gt(){return Xt.getInstanceById(...arguments)}function Yt(){return Xt.getOrCreateInstanceById(...arguments)}H.check();const Zt=o.Reflection.namespace("BX");Zt.AvatarEditor=Xt;e.Editor=Xt;e.MaskEditor=U;e.createInstance=Wt;e.getInstanceById=Gt;e.getOrCreateInstanceById=Yt;e.isCameraAvailable=Jt})(this.BX.UI.AvatarEditor=this.BX.UI.AvatarEditor||{},BX,BX,BX,BX.UI.EntitySelector,BX.UI.Dialogs,BX,BX,BX.Event,BX.Main,BX.UI,BX.UI.SidePanel);
//# sourceMappingURL=main.avatar-editor.bundle.map.js